python / python/mypy

Another circular import in `mypy/test/testreports.py`

Open
#17,726 3 comments 1 reaction 0 assignees View on GitHub

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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.