Dotted decorators on `TypedDict` classes fails for a certain package layout
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report, To Reproduce, & Actual Behaviour
I'm hitting a strange error in data_structures.py with the following project structure, with a potential culprit in runtime_validation.py:
Project/
└── package/
├── __init__.py
├── data_structures.py
└── runtime_validation.py
- Contents of
data_structures.pyimport typing as tp import package.runtime_validation as _runtime_validation # from package.runtime_validation import register_runtime_validator # Uncomment to make errors disappear deco = _runtime_validation.register_runtime_validator # OK @_runtime_validation.register_runtime_validator # OK class A: ... @_runtime_validation.register_runtime_validator # E: Module has no attribute "register_runtime_validator" class TD(tp.TypedDict): ... - Contents of
__init__.pyimport typing as tp RUNTIME_VALIDATORS: tp.Final = ... from package.data_structures import TD - Contents of
runtime_validation.pyimport typing as tp from package import RUNTIME_VALIDATORS # Comment out to make errors in `data_structures.py` disappear def register_runtime_validator(Type: type[tp.Any], /) -> type[tp.Any]: ... return Type
Expected Behavior
No issues
Your Environment
- Mypy version used: 1.11.1
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.10.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
Reproduce the issue using the package layout and contents shown in data_structures.py, init.py, and runtime_validation.py with mypy 1.11.1. Start by tracing how the import cycle affects attribute lookup for the dotted decorator on the TypedDict class. Done means the example reports no missing-attribute error without uncommenting the direct import.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100