attrs v21.3.0 Release Notes
Release Date: 2021-12-28 // over 2 years ago-
Backward-incompatible Changes
- 0️⃣ When using
@define
, converters are now run by default when setting an attribute on an instance -- additionally to validators. I.e. the new default ison_setattr=[attrs.setters.convert, attrs.setters.validate]
.
This is unfortunately a breaking change, but it was an oversight, impossible to raise a
DeprecationWarning
about, and it's better to fix it now while the APIs are very fresh with few users.#835 <https://github.com/python-attrs/attrs/issues/835>
,#886 <https://github.com/python-attrs/attrs/issues/886>
import attrs
has finally landed! As of this release, you can finally importattrs
using its proper name.
Not all names from the
attr
namespace have been transferred; most notablyattr.s
andattr.ib
are missing. Seeattrs.define
andattrs.field
if you haven't seen our next-generation APIs yet. A more elaborate explanation can be foundOn The Core API Names <https://www.attrs.org/en/latest/names.html>
_This feature is at least for one release provisional. We don't plan on changing anything, but such a big change is unlikely to go perfectly on the first strike.
The API docs have been mostly updated, but it will be an ongoing effort to change everything to the new APIs. Please note that we have not moved -- or even removed -- anything from
attr
!Please do report any bugs or documentation inconsistencies!
#887 <https://github.com/python-attrs/attrs/issues/887>
_🔄 Changes ^
attr.asdict(retain_collection_types=False)
(default) dumps collection-esque keys as tuples.#646 <https://github.com/python-attrs/attrs/issues/646>
,#888 <https://github.com/python-attrs/attrs/issues/888>
__match_args__
are now generated to support Python 3.10'sStructural Pattern Matching <https://docs.python.org/3.10/whatsnew/3.10.html#pep-634-structural-pattern-matching>
. This can be controlled by thematch_args
argument to the class decorators on Python 3.10 and later. On older versions, it is never added and the argument is ignored.#815 <https://github.com/python-attrs/attrs/issues/815>
- If the class-level on_setattr is set to
attrs.setters.validate
(default in@define
and@mutable
) but no field defines a validator, pretend that it's not set.#817 <https://github.com/python-attrs/attrs/issues/817>
_ - The generated
__repr__
is significantly faster on Pythons with f-strings.#819 <https://github.com/python-attrs/attrs/issues/819>
_ - Attributes transformed via
field_transformer
are wrapped withAttrsClass
again.#824 <https://github.com/python-attrs/attrs/issues/824>
_ - Generated source code is now cached more efficiently for identical classes.
#828 <https://github.com/python-attrs/attrs/issues/828>
_ - ➕ Added
attrs.converters.to_bool()
.#830 <https://github.com/python-attrs/attrs/issues/830>
_ attrs.resolve_types()
now resolves types of subclasses after the parents are resolved.#842 <https://github.com/python-attrs/attrs/issues/842>
_#843 <https://github.com/python-attrs/attrs/issues/843>
_- ➕ Added new validators:
lt(val)
(< val),le(va)
(≤ val),ge(val)
(≥ val),gt(val)
(> val), andmaxlen(n)
.#845 <https://github.com/python-attrs/attrs/issues/845>
_ attrs
classes are now fully compatible withcloudpickle <https://github.com/cloudpipe/cloudpickle>
_ (no need to disablerepr
anymore).#857 <https://github.com/python-attrs/attrs/issues/857>
_- ➕ Added new context manager
attrs.validators.disabled()
and functionsattrs.validators.(set|get)_disabled()
. They deprecateattrs.(set|get)_run_validators()
. All functions are interoperable and modify the same internal state. They are not – and never were – thread-safe, though.#859 <https://github.com/python-attrs/attrs/issues/859>
_ attrs.validators.matches_re()
now accepts pre-compiled regular expressions in addition to pattern strings.#877 <https://github.com/python-attrs/attrs/issues/877>
_
- 0️⃣ When using