[mypyc] cannot compile parameterized dataclass
Offen
Dieses Issue hat noch niemand übernommen.
bug
topic-dataclasses
topic-mypyc
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
mypyc can compile a parameterized dataclass, but it fails at import.
To Reproduce
- Make a file with
from __future__ import annotations
from dataclasses import dataclass
from typing import TypeVar, Generic
T = TypeVar("T")
class Foo(Generic[T]):
pass
@dataclass
class Bar(Foo[T]):
x: T
@property
def also_x(self) -> T:
return self.x
- Compile with mypyc (it appears that it works)
- Try importing Bar from file (to discover it does not work)
Actual Behavior
AttributeError Traceback (most recent call last)
...
----> 1 from test import Bar
File ~/.../test.py:15, in <module>
10 class Foo(Generic[T]):
11 pass
14 @dataclass
---> 15 class Bar(Foo[T]):
17 x: T
19 @property
20 def also_x(self) -> T:
AttributeError: attribute '__dict__' of 'type' objects is not writable
Your Environment
- Mypy version used: '0.950'
- Mypy command-line flags:
--strict - Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.9.12
- Operating system and version: macOS Monterey 12.4
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 mit dem parametrisierten Dataclass-Reproducer in test.py und kompiliere ihn mit mypyc unter Verwendung der gemeldeten Python- und mypy-Versionen. Überprüfe das Importverhalten des generierten Moduls und das Zusammenspiel von Dataclass, Generic[T] und der Property; als erledigt gilt es, wenn der Import von Bar ohne AttributeError erfolgreich ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100