`__slots__` is incorrectly classified as an instance variable across inheritance
維護者通常 1 天內回覆
評估
研究方向
先在 example.py 上使用 mypy 重現錯誤,然後追蹤繼承的 slots 如何針對一般宣告,以及由 dataclasses 和 attrs 透過 plugin 產生的 slots 進行分類。為這些情況新增覆蓋,並確認 mypy 不會回報類別與實例之間的覆寫錯誤。
由索引模型根據 Issue 內容生成。
描述
Bug Report
Mypy classifies __slots__ as an instance variable even though Python defines it on the class. This causes a false-positive override error when a subclass explicitly annotates __slots__ as a ClassVar.
The issue also affects plugin-generated __slots__, including slots generated by dataclasses and attrs.
To Reproduce
from dataclasses import dataclass
from typing import ClassVar
@dataclass(slots=True)
class Base:
x: float
y: float
class Child(Base):
__slots__: ClassVar[tuple[()]] = ()
Run:
mypy example.py
Playground link: https://mypy-play.net/?mypy=latest&python=3.14&gist=e0e2f906ab9e0201c43d2b5cb6ff950c
Expected Behavior
Mypy should report no errors. Both generated and explicitly declared __slots__ should be treated as class variables across inheritance.
Actual Behavior
Cannot override instance variable (previously declared on base class "Base") with class variable [misc]
A # type: ignore[misc] comment is currently required on the subclass declaration even though __slots__ is a class-level attribute.
The same inconsistent classification occurs with ordinary __slots__ declarations and attrs-generated slots.
Your Environment
- Mypy version used: 2.3.1
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.14.7
- 主要語言
- Python
- 星號
- 20.7k
- 分支
- 3.3k
- 平均合併
- 2 天 1 小時
- 30 天內合併 PR
- 104
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/mypy 的其他 Issue
-
T-string below Python 3.14 also reports import-not-found for string.templatelib on line 1可能已有人在做 @jw9829 於 3 天前認領。 未關閉bug topic-parser
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆
-
Regression in 2.4.0: empty constraint tuple in PEP 695 type parameter (`class C[T: ()]`) is no longer reported可能已有人在做 @CheerathAniketh 於 4 天前認領。 未關閉topic-parser topic-pep-695
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
`stubgen --inspect-mode` crashes with `AttributeError on PEP 604 union syntax (X | Y)` *(mypy 2.1.0)*可能已有人在做 @ayushdoesdev 於 72 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
Inconsistent description of `strict_optional`可能已有人在做 @Joosboy 於 88 天前認領。 未關閉documentation
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
相似的 Issue
-
Path subtraction removes repeated suffix characters instead of one suffix可能已有人在做 @Gwerdonatus 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
joke2k/django-environ#671 ·
-
good first issue help wanted windows
難度 2/5 1-3 小時 新手友好度 80/100
-
test_pgbouncer deploys the server under test from Charmhub instead of the local build (track/1.31)未關閉bug
難度 2/5 1-3 小時 新手友好度 68/100
canonical/temporal-k8s-operator#195 · 1 則留言 ·
維護者通常 4 天內回覆
-
`burr` fails to start when the Python path has a space in it可能已有人在做 @enekoreto 今天認領。 未關閉status/needs-triage
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 5 天內回覆
-
device support request
難度 2/5 1-3 小時 新手友好度 68/100
zigpy/zha-device-handlers#5461 ·
維護者通常 4 天內回覆