- cattrs version: 22.2.0
- Python version: 3.10.9
- Operating System: Linux
Description
Hi, first of all thanks for the amazing work, I've recently begun using both attrs and cattrs and I find them very useful and elegant.
I'm trying to structure some custom classes and all of my type annotations are recognized correctly, except for those using typing.Final.
What I Did
Here's a minmum example to reproduce the issue:
from typing import Final
from attrs import frozen
import cattrs
@frozen
class Foo:
a: Final[float]
cattrs.structure({"a": 1}, Foo)
Running this code results in a ClassValidationError with one sub-exception: a StructureHandlerNotFoundError which says "Unsupported type: Final[float]. Register a structure hook for it.".
Pitch
Final is one of the most basic type annotations in Python. Although I'm not familiar at all with cattrs internals, it shouldn't be too hard to add support for this type hint, as Final attributes should be structured and unstructured in the same way as their non-Finalcounterparts.
A Note About Frozen
attrs provides a frozen attribute (and I'm using that), but it's not the same thing. frozen operates at runtime, while Final can also be used during static analysis.
Description
Hi, first of all thanks for the amazing work, I've recently begun using both
attrsandcattrsand I find them very useful and elegant.I'm trying to structure some custom classes and all of my type annotations are recognized correctly, except for those using
typing.Final.What I Did
Here's a minmum example to reproduce the issue:
Running this code results in a
ClassValidationErrorwith one sub-exception: aStructureHandlerNotFoundErrorwhich says"Unsupported type: Final[float]. Register a structure hook for it.".Pitch
Finalis one of the most basic type annotations in Python. Although I'm not familiar at all withcattrsinternals, it shouldn't be too hard to add support for this type hint, asFinalattributes should be structured and unstructured in the same way as their non-Finalcounterparts.A Note About Frozen
attrsprovides afrozenattribute (and I'm using that), but it's not the same thing.frozenoperates at runtime, whileFinalcan also be used during static analysis.