Repository navigation
Releases
Releases · python-attrs/cattrs
v26.2.1
What's Changed
- Fix heterogeneous tuples and
NamedTuples with a member type containing a quote in itsrepr, liketuple[Literal["a"], int], crashing structuring code generation withSyntaxError; the index note is now embedded withrepr. (#777) - Fix
transform_errorlisting the extra keys of aForbiddenExtraKeysErrorin set iteration order, which made the message differ between runs; the keys are now sorted, like the error's own__str__already sorts them. (#776)
New Contributors
- @MaxFreedomPollard made their first contribution in #776
Full Changelog: v26.2.0...v26.2.1
v26.2.0
What's Changed
- Fix the
msgpackandcbor2converters unstructuring naive datetimes as local time, which made the serialized value depend on the timezone of the machine doing the unstructuring; naive datetimes are now assumed to be UTC, matching what the structure hooks already read back. (#774 #775) - Fix
override(rename=...)targets containing a quote (or other characters not safe in a bare string literal) crashing code generation withSyntaxError; the rename key is now embedded withrepr. (#771) - Fix
Counterkeys not being unstructured with the key type's own hook; the single-type-arg branch passed the whole type-args tuple to the key hook lookup instead of the key type. (#768) - Fix
create_default_dis_func(akacreate_uniq_field_dis_func) failing to disambiguate valid unions depending on the order of the member classes; unique fields are now resolved iteratively to a fixpoint. (#230 #765) - Support more recursive types on 3.14+ with specialized factories for
annotationlib.ForwardRef. (#740 #741) Converternow uses specialized hook factories to generate hooks for tuples, increasing speed. (#737)- Fix an
AttributeErrorincattrsinternals that could be triggered by using theinclude_subclassesstrategy in astructure_hook_factory(#721, #722) - Fix TypedDict codegen when keys contain single quotes. (#769)
- Add
CattrsErrorexception type: all exceptions raised bycattrsinherit from this.
Literal and date-time validation raise this directly, instead ofException. (#728) - Fix the
detailed_validationparameter being passed under the wrong name innamedtuple_dict_structure_factory, causing it to be silently ignored. (#723) - cattrs is now autoformatted using Ruff. (#732)
- Support running the test suite without
cbor2installed. (#748) - The union passthrough strategy now supports PEP 695 type aliases as union members. (#753)
BaseConverter.register_structure_hook_factoryandBaseConverter.register_unstructure_hook_factorynow properly return the factory when used as decorators. (#724)- The
msgspecpreconf converter now properly handles recursive classes on Python 3.14+. (#757)
New Contributors
- @mm-andritz made their first contribution in #722
- @bysiber made their first contribution in #723
- @yzhkali made their first contribution in #753
- @maxtaran2010 made their first contribution in #766
- @vineethsaivs made their first contribution in #765
- @uttam12331 made their first contribution in #768
- @winklemad made their first contribution in #771
- @onk3sh made their first contribution in #775
Full Changelog: v26.1.0...v26.2.0
v26.1.0
v26.1.0
- Add the
tomllibpreconf converter. See here for details. (#716) - Customizing un/structuring of attrs classes, dataclasses, TypedDicts and dict NamedTuples is now possible by using
Annotated[T, override()]on fields. See here for more details. (#717) - Fix structuring of nested generic classes with stringified annotations. (#688)
- Python 3.9 is no longer supported, as it is end-of-life. Use previous versions on this Python version. (#698)
- Apply the attrs converter to the default value before checking if it is equal to the attribute's value, when
omit_if_defaultis true and an attrs converter is specified. (#696) - Use the optional
_value_type hint to structure and unstructure enums if present. (#699) - Aliases (when in use) now properly generate rename metadata in generated hooks. (#706 #710)
- cattrs now tracks performance using codspeed. (#703)
- The
tomlkitpreconf converter now properly handles nativedateobjects when structuring. (#707 #708) - The
tomlkitpreconf converter now passes date objects directly to tomlkit for unstructuring. (#707 #708) - Enum handling has been optimized by switching to hook factories, improving performance especially for plain enums. (#705)
- Fix
cattrs.strategies.include_subclasseswhen used withcattrs.strategies.configure_tagged_unionand classes using diamond inheritance. (#685 #713) - Fix
cattrs.strategies.configure_tagged_unionwhen used with recursive type aliases. (#678 #714)
New Contributors
- @calebj made their first contribution in #688
- @antony-frolov made their first contribution in #696
- @reversefold made their first contribution in #702
Full Changelog: v25.3.0...v26.1.0
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).