Closed declaresub closed 6 months ago
Howdy,
I agree the new type aliases are really cool. I've landed support for them on the main branch a few weeks ago, so you can either wait for the 24.1.0 release, use the main branch (I try to keep it very stable) or look at https://github.com/python-attrs/cattrs/pull/452 for the changes to apply to a converter to have it support type aliases.
Almost all problems in cattrs are solved by registering hooks and this one is no different ;)
Structuring in cattrs supports union types represented by a TypeAlias, but not defined via type. Here's a bit of example code.
This does what one expects. But the next bit raises a StructureHandlerNotFoundError.
It would be nice if structure also accepted TypeAliasTypes.
Even though I know better, I suggest that implementation looks straightforward -- I made this change in converters,py around line 330:
after which I was able to structure data with type FooBar1. I note that I was unable to construct a type for which the while loop above would fail to terminate.