Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

`__slots__` is incorrectly classified as an instance variable across inheritance

Offen
#21,893 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
compilers, devtools

Rechercherichtung

Beginne damit, den Fehler mit mypy in example.py zu reproduzieren, und verfolge dann, wie geerbte slots für gewöhnliche Deklarationen und von Plugins erzeugte Slots aus dataclasses und attrs klassifiziert werden. Füge Abdeckung für diese Fälle hinzu und überprüfe, dass mypy keinen Fehler wegen einer Überschreibung zwischen Klasse und Instanz meldet.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug

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
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
Ø Merge
1 T. 3 Std.
Gemergte PRs (30 T.)
59

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/mypy

Alle Issues in python/mypy

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.