Versions follow CalVer with a strict backwards compatibility policy. The third digit is only for regressions.
Attributes now can have user-defined metadata which greatly improves
attrs‘s extensibility. #96
Allow for a
__attrs_post_init__method that – if defined – will get called at the end of the
@attr.s(str=True)that will optionally create a
__str__method that is identical to
__repr__. This is mainly useful with
Exceptions and other classes that rely on a useful
__str__implementation but overwrite the default one through a poor own one. Default Python class behavior is to use
If you tried using
Exceptions and were puzzled by the tracebacks: this option is for you.
attr.astuple()that – similarly to
attr.asdict()– returns the instance as a tuple. #77
- Converts now work with frozen classes. #76
- Instantiation of
attrsclasses with converters is now significantly faster. #80
- Pickling now works with
attr.assoc()now works with
- The tuple returned by
attr.fields()now also allows to access the
Attributeinstances by name. Yes, we’ve subclassed
tupleso you don’t have to! Therefore
attr.fields(C).xis equivalent to the deprecated
C.xand works with
- All instances where function arguments were called
clhave been changed to the more Pythonic
cls. Since it was always the first argument, it’s doubtful anyone ever called those function with in the keyword form. If so, sorry for any breakage but there’s no practical deprecation path to solve this ugly wart.
Attributeinstances on class objects is now deprecated and will stop working in 2017. If you need introspection please use the
__attrs_attrs__attribute or the
attr.fields()function that carry them too. In the future, the attributes that are defined on the class body and are usually overwritten in your
__init__method are simply removed after
@attr.shas been applied.
This will remove the confusing error message if you write your own
__init__and forget to initialize some attribute. Instead you will get a straightforward
AttributeError. In other words: decorated classes will work more like plain Python classes which was always
The serious business aliases
attr.attrhave been deprecated in favor of
attr.attribwhich are much more consistent and frankly obvious in hindsight. They will be purged from documentation immediately but there are no plans to actually remove them.
dict_factoryarguments is now propagated on recursion. #45
attr.fields()are significantly faster. #48 #51
attr.attribas a more consistent aliases for
attr.sthat will make instances best-effort immutable. #60
retain_collection_typesas an argument. If
True, it does not convert attributes of type
Python 3.3 and 2.6 aren’t supported anymore. They may work by chance but any effort to keep them working has ceased.
The last Python 2.6 release was on October 29, 2013 and isn’t supported by the CPython core team anymore. Major Python packages like Django and Twisted dropped Python 2.6 a while ago already.
Python 3.3 never had a significant user base and wasn’t part of any distribution’s LTS release.
__slots__have arrived! Classes now can automatically be slots-style (and save your precious memory) just by passing
- Allow the case of initializing attributes that are set to
init=False. This allows for clean initializer parameter lists while being able to initialize attributes to default values. #32
attr.asdict()can now produce arbitrary mappings instead of Python
dicts when provided with a
- Multiple performance improvements.