Hello,
I have just found an issue with the configure_union_passthrough strategy, when using the 3.12 type alias as an element of a union to structure.
Here is my attempt at an MRE, tested on Python 3.12:
import dataclasses
import typing
import cattrs
import cattrs.strategies
converter = cattrs.Converter()
cattrs.strategies.configure_union_passthrough(str | int, converter)
@dataclasses.dataclass
class DataClass:
field: str
type NewScalar = str
OldScalar: typing.TypeAlias = str
if __name__ == "__main__":
data = {"field": "value"}
v1 = converter.structure(data, OldScalar | DataClass) # This one works
print(v1)
v2 = converter.structure(data, NewScalar | DataClass) # This one does not work
print(v2)
The line before last raises cattrs.errors.StructureHandlerNotFoundError: Unsupported type: NewScalar | __main__.DataClass. Register a structure hook for it.