Incorrect `__qualname__` in slotted dataclasses in `__init_subclass__`
未关闭
还没有人认领这个 Issue。
stdlib
topic-dataclasses
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
In the following:
import dataclasses
@dataclasses.dataclass(slots=True)
class Base:
def __init_subclass__(cls) -> None:
print(cls.__qualname__)
class Container:
@dataclasses.dataclass(slots=True)
class Dataclass(Base):
pass
I get:
Container.Dataclass
Dataclass
(I can handle the double-call, but the second call having incorrect __qualname__ is just really annoying 😂 )
To clarify the annoyance, the real world use case looks something like:
@dataclasses.dataclass(slots=True)
class Base:
def __init_subclass__(cls) -> None:
if "__slots__" not in cls.__dict__:
return # We're the unslotted class, wait until we're the slotted "real" one
... # Some code here relying on `__qualname__`
CPython versions tested on:
3.11
Operating systems tested on:
macOS
Linked PRs
- gh-129916
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行 issue 中嵌套的 slotted-dataclass 复现用例,并阅读链接的 PR gh-129916。追踪第二次调用 init_subclass 前后 dataclasses 对 slots 的处理,然后添加或运行一个回归测试,证明嵌套类保留了正确的 qualname。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100