`__slots__` is incorrectly classified as an instance variable across inheritance
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
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
Start by reproducing the error with mypy on example.py, then trace how inherited slots are classified for ordinary declarations and plugin-generated slots from dataclasses and attrs. Add coverage for these cases and verify that mypy reports no class-versus-instance override error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100