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
SerializableType.__init_subclass__() does not call object.__init_subclass__(), making it impossible to use PEP 695 syntax on subclasses of SerializableType.
What I Did
The following example creates a generic SerializableType subclass using PEP 695 syntax.
It should be possible to use the generic type using the Foo[int] syntax, but this leads to an AttributeError.
Traceback (most recent call last):
File "[...]/example.py", line 12, in <module>
class Model(DataClassDictMixin):
File "[...]/example.py", line 13, in Model
int_foo: Foo[int]
~~~^^^^^
File "[...]/opt/homebrew/Cellar/[email protected]/3.12.8/Frameworks/Python.framework/Versions/3.12/lib/python3.12/typing.py", line 395, in inner
return _caches[func](*args, **kwds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[...]/opt/homebrew/Cellar/[email protected]/3.12.8/Frameworks/Python.framework/Versions/3.12/lib/python3.12/typing.py", line 1106, in _generic_class_getitem
for param in cls.__parameters__:
^^^^^^^^^^^^^^^^^^
AttributeError: type object 'Foo' has no attribute '__parameters__'
Exit code: 1
The problem is that __parameters__ on SerializableType does not get initialized, which is probably done by object.__init_subclass__(). SerializableType.__init_subclass__() does not call object.__init_subclass__(), which leads to this problem.
The text was updated successfully, but these errors were encountered:
I had a go at creating a PR, please have a look. I tried creating an appropriate test case based on what I found. Please provide feedback or suggestions if you'd like this to be done differently. :)
Description
SerializableType.__init_subclass__()
does not callobject.__init_subclass__()
, making it impossible to use PEP 695 syntax on subclasses ofSerializableType
.What I Did
The following example creates a generic
SerializableType
subclass usingPEP 695
syntax.It should be possible to use the generic type using the
Foo[int]
syntax, but this leads to anAttributeError
.The problem is that
__parameters__
onSerializableType
does not get initialized, which is probably done byobject.__init_subclass__()
.SerializableType.__init_subclass__()
does not callobject.__init_subclass__()
, which leads to this problem.The text was updated successfully, but these errors were encountered: