Spurious “cyclic definition” error when inheriting from and shadowing a class
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Shadowing class names and inheriting from the previous class causes the following error:
Cannot resolve name "{shadowed class name}" (possible cyclic definition)
To Reproduce
Attempt to typecheck the following code:
class MyError(Exception): pass
class RuntimeError(RuntimeError, MyError): pass
Expected Behavior
Accepted by Mypy, RuntimeError can now be imported from that file and refers to a subclass of MyError.
Actual Behavior
file.py: 2: error: Cannot resolve name "RuntimeError" (possible cyclic definition)
Your Environment
- Mypy version used: 0.812
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.8.9
- Operating system and version: NixOS unstable
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 by reproducing the error with the two-class Python snippet under mypy 0.812, then trace how class base names are resolved when a class shadows an inherited name. Done means mypy accepts the example without the cyclic-definition error and the resulting RuntimeError remains importable as a subclass of MyError.
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
- 38/100