You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
can't specify generic types when instantiating frozen dataclass with slots #116669
FYI: this doesn't relate to the new (PEP 695) syntax.
Example with the old syntax:
fromdataclassesimportdataclassfromtypingimportTypeVar, GenericT=TypeVar("T")
@dataclass(frozen=True, slots=True)classFoo(Generic[T]):
passfoo=Foo() # this line worksfoo=Foo[int]() # this one does not
Traceback (mostrecentcalllast):
File"/home/eclips4/CLionProjects/cpython/example.py", line13, in<module>foo=Foo[int]() # this one does not^^^^^^^^^^File"/usr/local/lib/python3.11/typing.py", line1277, in__call__result.__orig_class__=self^^^^^^^^^^^^^^^^^^^^^File"<string>", line5, in__setattr__TypeError: super(type, obj): objmustbeaninstanceorsubtypeoftype
Happily, this specific exception was fixed just last month, in #115213. The fix was backported, so it will be included in the next releases of Python 3.12 and Python 3.11. The typing module is in the clear here.
However, it looks like dataclasses might also be using super() incorrectly there? Not sure.
This is a symptom of the general problem where slotted dataclasses work by creating a new class, which breaks super(). There are several other similar issues and there's no obvious solution.
This is a symptom of the general problem where slotted dataclasses work by creating a new class, which breaks super(). There are several other similar issues and there's no obvious solution.
If there are already other similar issues regarding super() in dataclasses, then we can probably close this one, as the user-visible bug here has already been fixed by #115213
Activity
Eclips4 commentedon Mar 12, 2024
FYI: this doesn't relate to the new (PEP 695) syntax.
Example with the old syntax:
AlexWaygood commentedon Mar 12, 2024
Happily, this specific exception was fixed just last month, in #115213. The fix was backported, so it will be included in the next releases of Python 3.12 and Python 3.11. The
typingmodule is in the clear here.However, it looks like
dataclassesmight also be usingsuper()incorrectly there? Not sure.Eclips4 commentedon Mar 12, 2024
JelleZijlstra commentedon Mar 12, 2024
This is a symptom of the general problem where slotted dataclasses work by creating a new class, which breaks
super(). There are several other similar issues and there's no obvious solution.cc @ericvsmith for dataclasses.
AlexWaygood commentedon Mar 12, 2024
If there are already other similar issues regarding
super()in dataclasses, then we can probably close this one, as the user-visible bug here has already been fixed by #115213JelleZijlstra commentedon Mar 12, 2024
https://github.com/python/cpython/issues?q=is%3Aissue+is%3Aopen+dataclasses+slots+super lists several.
AlexWaygood commentedon Mar 12, 2024
Thanks for the report, @daddinuz! Your bug was valid; we'd just already fixed it before you filed the issue ;)