Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(🐞) errors from imported modules aren't reported when project is installed #18106

Open
KotlinIsland opened this issue Nov 5, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Nov 5, 2024

given

-src
 |- __init__.py
 |- test.py
 |- test2.py
# src/test.py
from src import test2

reveal_type(test2.a)
# src/test2.py
1 + ""
a = 1

then

> mypy -m src.test
src/test.py:4: note: Revealed type is "builtins.int"
Success: no issues found in 1 source file
> mypy src/test
src/test.py:4: note: Revealed type is "builtins.int"
Success: no issues found in 1 source file

expected

reference

Mypy is designed to doggedly follow all imports, even if the imported module is not a file you explicitly wanted mypy to check.

--follow-imports=normal follows all imports normally and type checks all top level code (as well as the bodies of all functions and methods with at least one type annotation in the signature).

> mypy src/test.py
src/test2.py:1: error: Unsupported operand types for + ("int" and "str")  [operator]
src/test.py:4: note: Revealed type is "builtins.int"
Found 1 error in 1 file (checked 3 source files)

type checks all code

where are the errors from this typechecking?

i found them

> mypy --no-silence-site-packages -m src.test
src/test2.py:1: error: Unsupported operand types for + ("int" and "str")  [operator]
src/test.py:4: note: Revealed type is "builtins.int"

uhhhh, what?

Enables reporting error messages generated within installed packages (see PEP 561 for more details on distributing type information). Those error messages are suppressed by default, since you are usually not able to control errors in 3rd party code.

> mypy -m src.test
src/test.py:4: note: Revealed type is "builtins.int"
Success: no issues found in 1 source file
> uv pip uninstall -e .
...
> mypy -m src.test
src/test2.py:1: error: Unsupported operand types for + ("int" and "str")  [operator]
src/test.py:4: note: Revealed type is "builtins.int"
Found 1 error in 1 file (checked 1 source file)
@KotlinIsland KotlinIsland added the bug mypy got something wrong label Nov 5, 2024
@KotlinIsland KotlinIsland changed the title (🐞) errors from imported modules aren't reported when project is isntalled (🐞) errors from imported modules aren't reported when project is installed Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant