Another circular import in `mypy/test/testreports.py`
Open
Nobody has claimed this yet.
bug
topic-developer
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Running the testreports module in isolation reveals a circular import similar to #15570.
To Reproduce
$ tox r -e py311 -- mypy/test/testreports.py
Expected Behavior
It should collect the tests from the module.
Actual Behavior
______________________________________________________________________________ ERROR collecting mypy/test/testreports.py _______________________________________________________________________________
ImportError while importing test module '~/src/github/python/mypy/mypy/test/testreports.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.11/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
mypy/test/testreports.py:7: in <module>
from mypy.report import CoberturaPackage, get_line_rate
mypy/report.py:19: in <module>
from mypy import stats
mypy/stats.py:11: in <module>
from mypy.argmap import map_formals_to_actuals
mypy/argmap.py:8: in <module>
from mypy.maptype import map_instance_to_supertype
mypy/maptype.py:3: in <module>
from mypy.expandtype import expand_type_by_instance
mypy/expandtype.py:7: in <module>
from mypy.types import (
mypy/types.py:3751: in <module>
from mypy.expandtype import ExpandTypeVisitor
E ImportError: cannot import name 'ExpandTypeVisitor' from partially initialized module 'mypy.expandtype' (most likely due to a circular import) (~/src/github/python/mypy/mypy/expandtype.py)
Your Environment
- Mypy version used:
master - Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: Python 3.11
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
Start with the tox command from the report and inspect the import chain from mypy/test/testreports.py through mypy/report.py, mypy/stats.py, mypy/argmap.py, mypy/maptype.py, mypy/expandtype.py, and mypy/types.py. Confirm the circular-import failure, then verify that running the test module collects its tests successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100