#python #type-hinting #mypy #python-typing
Вопрос:
Версии:
Python 3.9.1
mypy==0.910
Я не уверен, почему mypy будет выводить другой набор ошибок при запуске с mypy .
vs при запуске с mypy <path to file>
При запуске mypy . --strict --show-error-codes
результат отличается от выполнения mypy <path to file> --strict --show-error-codes
.
Например, просмотр кода из https://github.com/raphaelvallat/pingouin (идентификатор фиксации ea8b560
, файл, используемый в качестве примера здесь: https://github.com/raphaelvallat/pingouin/blob/f40df480e137af8df35a3a3164d2d900b79091a6/pingouin/utils.py#L10
).
Бег : mypy . --strict --show-error-codes --exclude "./venv/"
дает:
(venv) ➜ pingouin git:(master) ✗ mypy . --strict --show-error-codes --exclude "./venv/" > mypy_all_files.txt
(venv) ➜ pingouin git:(master) ✗ grep "pingouin/utils.py" mypy_all_files.txt
pingouin/utils.py:3: error: Cannot find implementation or library stub for module named "numpy" [import]
pingouin/utils.py:4: error: Cannot find implementation or library stub for module named "pandas" [import]
pingouin/utils.py:7: error: Library stubs not installed for "tabulate" (or incompatible with Python 3.9) [import]
pingouin/utils.py:7: note: Hint: "python3 -m pip install types-tabulate"
pingouin/utils.py:7: note: (or run "mypy --install-types" to install all missing stub packages)
pingouin/utils.py:440: error: Cannot find implementation or library stub for module named "statsmodels" [import]
pingouin/utils.py:454: error: Cannot find implementation or library stub for module named "sklearn" [import]
pingouin/utils.py:468: error: Cannot find implementation or library stub for module named "mpmath" [import]
И бег mypy ./pingouin/utils.py --strict --show-error-codes > mypy_single_file.txt
дает:
(venv) ➜ pingouin git:(master) ✗ mypy ./pingouin/utils.py --strict --show-error-codes > mypy_single_file.txt
(venv) ➜ pingouin git:(master) ✗ grep "pingouin/utils.py" mypy_single_file.txt
pingouin/utils.py:3: error: Cannot find implementation or library stub for module named "numpy" [import]
pingouin/utils.py:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
pingouin/utils.py:4: error: Cannot find implementation or library stub for module named "pandas" [import]
pingouin/utils.py:7: error: Library stubs not installed for "tabulate" (or incompatible with Python 3.9) [import]
pingouin/utils.py:7: note: Hint: "python3 -m pip install types-tabulate"
pingouin/utils.py:7: note: (or run "mypy --install-types" to install all missing stub packages)
pingouin/utils.py:16: error: Function is missing a type annotation [no-untyped-def]
pingouin/utils.py:54: error: Function is missing a type annotation [no-untyped-def]
pingouin/utils.py:78: error: Function is missing a type annotation [no-untyped-def]
pingouin/utils.py:113: error: Call to untyped function "_get_round_setting_for" in typed context [no-untyped-call]
pingouin/utils.py:140: error: Function is missing a type annotation [no-untyped-def]
pingouin/utils.py:157: error: Function is missing a type annotation [no-untyped-def]
pingouin/utils.py:176: error: Function is missing a type annotation [no-untyped-def]
pingouin/utils.py:225: error: Call to untyped function "_remove_na_single" in typed context [no-untyped-call]
pingouin/utils.py:227: error: Call to untyped function "_remove_na_single" in typed context [no-untyped-call]
pingouin/utils.py:232: error: Call to untyped function "_remove_na_single" in typed context [no-untyped-call]
pingouin/utils.py:235: error: Call to untyped function "_remove_na_single" in typed context [no-untyped-call]
pingouin/utils.py:236: error: Call to untyped function "_remove_na_single" in typed context [no-untyped-call]
pingouin/utils.py:260: error: Function is missing a type annotation [no-untyped-def]
pingouin/utils.py:303: error: Call to untyped function "_flatten_list" in typed context [no-untyped-call]
pingouin/utils.py:341: error: Function is missing a type annotation [no-untyped-def]
pingouin/utils.py:379: error: Call to untyped function "_flatten_list" in typed context [no-untyped-call]
pingouin/utils.py:382: error: Call to untyped function "_flatten_list" in typed context [no-untyped-call]
pingouin/utils.py:390: error: Function is missing a type annotation [no-untyped-def]
pingouin/utils.py:399: error: Function is missing a type annotation [no-untyped-def]
pingouin/utils.py:437: error: Function is missing a type annotation [no-untyped-def]
pingouin/utils.py:440: error: Cannot find implementation or library stub for module named "statsmodels" [import]
pingouin/utils.py:451: error: Function is missing a type annotation [no-untyped-def]
pingouin/utils.py:454: error: Cannot find implementation or library stub for module named "sklearn" [import]
pingouin/utils.py:465: error: Function is missing a type annotation [no-untyped-def]
pingouin/utils.py:468: error: Cannot find implementation or library stub for module named "mpmath" [import]
Последнее-это то, что мне было бы более интересно увидеть, и я ожидал бы, что другие тоже будут.
Я не уверен, в чем разница и как использовать последний вывод по умолчанию.
Комментарии:
1. Я не могу повторить это. Какую версию
mypy
иpython
используете ли вы?2. 🤔Это похоже на регрессию. Я обновил с
mypy
0.770 до 0.910, и я вижу аналогичное поведение.3. Извините, добавлю версии для публикации
4. Проверьте нижнюю часть вывода для вашей
mpy .
версии. У меня есть такая строчкаFound 1 error in 1 file (errors prevented further checking)
. Я думаю, ты тоже можешь. Я полагаю, это означает, что какая-то ошибка в каком-то файле остановилаmypy
продолжение проверки других файлов. Хотя я не знаю, что такое поведение существует.5. Мое лучшее предположение состоит в том, что это было изменение в том, как
mypy
рекурсивно выполняется поиск модулей в 0.800. Проверьте список изменений и подробную документацию по поиску