class decorator syntax seems to ignore dataclasses' constructor signatures
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
This code sample gives errors on the presence of f in X's constructor but not on DX's
from __future__ import annotations
from typing import Callable, Type
from dataclasses import dataclass
def clsdec(x: Callable[[int, str, object], object]) -> Type:
return x # type: ignore
@clsdec
class X(object):
def __init__(self, x: int, y: str, z: object, f: float) -> None:
pass
@clsdec
@dataclass
class DX(object):
x: int
y: str
z: object
f: float
It seems like it can't "see" the dataclass's fields somehow, despite otherwise reporting sensible errors at the call site.
In fact, clsdec(DX) gives the same error; it's only a problem when it's used in the decorator position.
Your Environment
- Mypy version used: mypy 0.961 (compiled: yes)
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: Python 3.10.4 (python.org)
- Operating system and version:
ProductName: macOS
ProductVersion: 12.4
BuildVersion: 21F79
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, das mitgelieferte Beispiel mit mypy 0.961 auszuführen, und vergleiche die Diagnosen für den Fall an der Decorator-Position mit dem direkten Aufruf clsdec(DX). Verfolge die Verarbeitung von Decorator und dataclass-Signatur; abgeschlossen ist die Aufgabe, wenn die Konstruktorsignatur für beide Formen gleichwertig geprüft wird und dies durch einen Regressionstest abgedeckt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100