Dotted decorators on `TypedDict` classes fails for a certain package layout
未关闭
还没有人认领这个 Issue。
bug
- 主要语言
- Python
- 星标
- 20.6k
- 派生
- 3.3k
- PR 合并指标
- PR 指标待抓取
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用 data_structures.py、init.py 和 runtime_validation.py 中所示的软件包布局和内容,通过 mypy 1.11.1 重现该问题。首先跟踪导入循环如何影响 TypedDict 类上点号装饰器的属性查找。无需取消直接导入的注释,且示例不再报告缺少属性错误,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100