New
v25.1.0
- Potentially breaking: The converters raise
StructureHandlerNotFoundErrormore eagerly (on hook creation, instead of on hook use). This helps surfacing problems with missing hooks sooner. See Migrations for steps to restore legacy behavior. (#577) - Add a Migrations page, with instructions on migrating changed behavior for each version. (#577)
typing.Selfis now supported in attrs classes, dataclasses, TypedDicts and the dict NamedTuple factories. Seetyping.Selffor details. (#299 #627)- PEP 695 type aliases can now be used with
BaseConverter.register_structure_hookandBaseConverter.register_unstructure_hook. Previously, they required the use ofBaseConverter.register_structure_hook_func(which is still supported). (#647) - Expose
cattrs.cols.mapping_unstructure_factorythroughcattrs.cols. - Some
defaultdictsare now supported by default, andcattrs.cols.is_defaultdictandcattrs.cols.defaultdict_structure_factoryare exposed throughcattrs.cols. (#519 #588) - Generic PEP 695 type aliases are now supported. (#611 #618)
- The tagged union strategy now also supports type aliases of unions. (#649)
Converter.copyandBaseConverter.copyare correctly annotated as returningSelf. (#644)- Many preconf converters (bson, stdlib JSON, cbor2, msgpack, msgspec, orjson, ujson) skip unstructuring
intandstrenums, leaving them to the underlying libraries to handle with greater efficiency. (#598) - The msgspec JSON preconf converter now handles dataclasses with private attributes more efficiently. (#624)
- Literals containing enums are now unstructured properly, and their unstructuring is greatly optimized in the bson, stdlib JSON, cbor2, msgpack, msgspec, orjson and ujson preconf converters. (#598)
- Preconf converters now handle dictionaries with literal keys properly. (#599)
- Structuring TypedDicts from invalid inputs now properly raises a
ClassValidationError. (#615 #616) cattrs.strategies.include_subclassesnow properly works with generic parent classes. (#649)- Replace
cattrs.gen.MappingStructureFnwithcattrs.SimpleStructureHook. - Python 3.13 is now supported. (#543 #547)
- Python 3.8 is no longer supported, as it is end-of-life. Use previous versions on this Python version. (#591)
- Change type of
Converter.__init__.unstruct_collection_overridesfromCallabletoMapping[type, UnstructureHook](#594). - Adopt the Contributor Covenant Code of Conduct (just like attrs).