`attr-defined` on modules depends on imports in other files
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
I'm not sure how to put together a good description of this, but here goes: mypy emits attr-defined errors (correctly) when importing concurrent (but not concurrent.futures), and then using concurrent.futures. However, if checking another file in the same pass which does import concurrent.futures, it doesn't emit an error for the first file.
To Reproduce
Create file a.py:
import concurrent
concurrent.futures
Create file b.py:
import concurrent.futures
concurrent.futures
Expected Behavior
Should emit an error for a.py, regardless of which other files are also being checked:
$ python -m mypy --no-incremental --cache-dir=/dev/null a.py
a.py:3: error: Module has no attribute "futures" [attr-defined]
Found 1 error in 1 file (checked 1 source file)
$ python3 -m mypy --no-incremental --cache-dir=/dev/null a.py b.py
a.py:3: error: Module has no attribute "futures" [attr-defined]
Found 1 error in 1 file (checked 2 source files)
Actual Behavior
$ python -m mypy --no-incremental --cache-dir=/dev/null a.py
a.py:3: error: Module has no attribute "futures" [attr-defined]
Found 1 error in 1 file (checked 1 source file)
$ python -m mypy --no-incremental --cache-dir=/dev/null a.py b.py
Success: no issues found in 2 source files
Your Environment
- Mypy version used: tried both 1.11.2 and mypy-1.12.0+dev.0412590ba13395a04f122a5dd83764db9d001fe6
- Mypy command-line flags:
--no-incremental --cache-dir=/dev/null, just because it's less confusing that way. I was also seeing this with caching - Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided a.py and b.py files, using python -m mypy --no-incremental --cache-dir=/dev/null on each file and together. Start by tracing module attribute handling during multi-file checking; done means a.py consistently reports the missing futures attribute regardless of whether b.py is checked.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100