python / python/mypy

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

Open
#18,106 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the provided src/test.py and src/test2.py examples, comparing mypy -m src.test, mypy src/test.py, and --no-silence-site-packages before and after installation. Trace import following and installed-package error suppression, including the PEP 561 behavior referenced in the issue. Done means errors from the imported module are reported in the intended case without breaking normal third-party suppression.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.