Releases: python-attrs/cattrs
Releases · python-attrs/cattrs
v25.3.0
- Potentially breaking: Abstract sets are now structured into frozensets.
This allows hashability, better immutability and is more consistent with thecollections.abc.Settype.
See Migrations for steps to restore legacy behavior. (#686) - Python 3.14 is now supported and part of the test matrix. (#653)
- Fix unstructuring NewTypes with the {class}
BaseConverter. (#684) - Make some Hypothesis tests more robust. (#684)
- {func}
cattrs.strategies.include_subclassesnow works with generic parent classes and the tagged union strategy. (#683)
New Contributors
Full Changelog: v25.2.0...v25.3.0
v25.2.0
- Potentially breaking: Sequences are now structured into tuples.
This allows hashability, better immutability and is more consistent with thecollections.abc.Sequencetype. See Migrations for steps to restore legacy behavior. (#663) - Add a
use_aliasparameter tocattrs.Converter.
cattrs.gen.make_dict_unstructure_fn_from_attrs,cattrs.gen.make_dict_unstructure_fn,
cattrs.gen.make_dict_structure_fn_from_attrs,cattrs.gen.make_dict_structure_fn
andcattrs.gen.typeddicts.make_dict_structure_fnwill use the value for theuse_aliasparameter from the given converter by default now. If you're using these functions directly, the old behavior can be restored by passing in the desired value directly. (#596 #660) - The union passthrough strategy now by default accepts ints for unions that contain floats but not ints,
when configured to be able to handle both ints and floats. This more closely matches the current typing behavior. (#656 #668) - Fix unstructuring of generic classes with stringified annotations. (#661 #662)
- For
cattrs.errors.StructureHandlerNotFoundErrorandcattrs.errors.ForbiddenExtraKeysError
correctly setBaseException.argsinsuper()and hence make them pickable. (#666) - The default disambiguation hook factory is now only enabled for converters with
unstructure_strat=AS_DICT(the default).
Since the strategy doesn't support tuples, it is skipped forunstructure_strat=AS_TUPLEconverters. (#673) - Switch to
uvandjustin lieu of PDM, tox and Make. See the Contributing section for new workflow instructions. (#671)
New Contributors
- @hoodmane made their first contribution in #665
- @carltongibson made their first contribution in #677
Full Changelog: v25.1.1...v25.2.0
v25.1.1
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, and
cattrs.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).
v24.1.3
v24.1.2
24.1.1
24.1.0
- Potentially breaking: Unstructuring hooks for
typing.Anyare consistent now: values are unstructured using their runtime type.
Previously this behavior was underspecified and inconsistent, but followed this rule in the majority of cases.
Reverting old behavior is very dependent on the actual case; ask on the issue tracker if in doubt.
(#473) - Minor change: Heterogeneous tuples are now unstructured into tuples instead of lists by default; this is significantly faster and widely supported by serialization libraries.
(#486) - Minor change:
cattrs.gen.make_dict_structure_fnwill use the value for theprefer_attrib_convertersparameter from the given converter by default now.
If you're using this function directly, the old behavior can be restored by passing in the desired values explicitly.
(#527 #528) - Introduce
BaseConverter.get_structure_hookandBaseConverter.get_unstructure_hookmethods.
(#432 #472) BaseConverter.register_structure_hook,BaseConverter.register_unstructure_hook,
BaseConverter.register_unstructure_hook_factoryandBaseConverter.register_structure_hook_factory
can now be used as decorators and have gained new features.
See here and here for more details.
(#487)- Introduce and document the
cattrs.colsmodule for better collection customizations.
(#504 #540) - Enhance the
cattrs.cols.is_mappingpredicate function to also cover virtual subclasses ofabc.Mapping.
This enables map classes from libraries such as immutables or sortedcontainers to structure out-of-the-box.
(#555 #556) - Introduce the msgspec
preconf converter <cattrs.preconf.msgspec>.
Only JSON is supported for now, with other formats supported by msgspec to come later.
(#481) - The default union handler now properly takes renamed fields into account.
(#472) - The default union handler now also handles dataclasses.
(#426 #477) - Add support for PEP 695 type aliases.
(#452) - Add support for PEP 696
TypeVars with defaults.
(#512) - Add support for named tuples with type metadata (
typing.NamedTuple).
(#425 #491) - Add support for optionally un/unstructuring named tuples using dictionaries.
(#425 #549) - The
include_subclassesstrategy now fetches the member hooks from the converter (making use of converter defaults) if overrides are not provided, instead of generating new hooks with no overrides.
(#429 #472) - The preconf
make_converterfactories are now correctly typed.
(#481) - The
orjson preconf converternow passes through dates and datetimes to orjson while unstructuring, greatly improving speed.
(#463) cattrs.gengenerators now attach metadata to the generated functions, making them introspectable.
(#472)- Structure hook factories in
cattrs.gennow handle recursive classes better.
(#540) - The tagged union strategy now leaves the tags in the payload unless
forbid_extra_keysis set.
(#533 #534) - More robust support for
AnnotatedandNotRequiredin TypedDicts.
(#450) typing_extensions.Literalis now automatically structured, just liketyping.Literal.
(#460 #467)typing_extensions.Anyis now supported and handled liketyping.Any.
(#488 #490)Optionaltypes can now be consistently customized usingregister_structure_hookandregister_unstructure_hook.
(#529 #530)- The BaseConverter now properly generates detailed validation errors for mappings.
(#496) - PEP 695 generics are now tested.
(#452) - Imports are now sorted using Ruff.
- Tests are run with the pytest-xdist plugin by default.
- Rework the introductory parts of the documentation, introducing the Basics section.
(#472) - The documentation has been significantly reworked.
(#473) - The docs now use the Inter font.
- Make type annotations for
include_subclassesandtagged_unionstrategies more lenient.
(#431)