Inconsistent dataclass declaration
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 5.1k
- Forks
- 2.1k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 82
Beschreibung
The dataclass decorator in the typeshed package has an inconsistency in its overloads. Specifically, when cls is passed explicitly as None, it is unclear whether additional arguments (e.g., init, repr, etc.) should be allowed or not. The current implementation allows passing cls=None alongside additional arguments, but this usage is not explicitly documented or validated.
Expected Behavior
The overloads should clearly define and document the behavior of cls=None when additional arguments are provided:
If allowed, the typing should reflect that explicitly.
If not allowed, the implementation should prevent or warn against such usage.
Current Behavior
Passing cls=None with arguments like kw_only=True is allowed, but this behavior is not described in the overloads. For example:
decorator = dataclass(None, kw_only=True)
@decorator
class MyClass:
x: int
The above works but is ambiguous in terms of type checking and intended usage.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die Überladungen des Decorators dataclass im typeshed-Paket zu finden, und vergleiche sie mit dem gezeigten Beispiel dataclass(None, kw_only=True). Kläre, ob cls=None mit zusätzlichen Argumenten unterstützt wird, und bringe anschließend die Überladungen und die Dokumentation dazu, diese Entscheidung konsistent auszudrücken. Erledigt ist die Aufgabe, wenn das Verhalten für Type Checker und Benutzer eindeutig ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 35/100