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:
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
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 aClassVar.The issue also affects plugin-generated
__slots__, including slots generated by dataclasses and attrs.To Reproduce
Run:
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
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.ini(and other config files): none