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
Not a particularly pressing bug, and perhaps a bug in beartype rather than pyserde.
Workarounds are documented below.
To reproduce:
fromtypingimportGeneric, TypeVarimportserde# Assuming CustomInt must be declared after T# we need to use a string for the union type boundT=TypeVar("T", bound="int | CustomInt")
classCustomInt(int):
pass# This fails with# `beartype.roar.BeartypeDecorHintForwardRefException: Forward reference 'int | CustomInt' not valid Python attribute name.`@serde.serdeclassFoo(Generic[T]):
bar: T
Workarounds:
Define CustomInt class before the type var, so that a string type annotation is not needed. However, this may not always be possible perhaps?
Use the typing.Union instead of Union syntax:
T=TypeVar("T", bound=Union[int, "CustomInt"])
The text was updated successfully, but these errors were encountered:
I think actually, in the bigger picture, there is lack of support / limitation for generic fields anyway.
It seems that deserializing with Foo[CustomInt], or just Foo as the target type, just returns the field as a dict, rather than trying to serialize to the specified generic.
Not a particularly pressing bug, and perhaps a bug in beartype rather than pyserde.
Workarounds are documented below.
To reproduce:
Workarounds:
The text was updated successfully, but these errors were encountered: