Overview
attrs 21.3, released on December 28, 2021, introduces import attrs as a new namespace and adds match_args support for pattern matching.
Main Features
attrs namespace
The new import attrs namespace with attrs.define replaces the old @attr.s, offering a more modern API.
python
import attrs
@attrs.define
class Point:
x: float
y: float
p = Point(1.0, 2.0)
print(p) # Point(x=1.0, y=2.0)
match_args
__match_args__ support lets attrs classes work with Python 3.10+ pattern matching.
python
import attrs
@attrs.define
class Command:
action: str
target: str
cmd = Command('move', 'north')
match cmd:
case Command('move', direction):
print(f'Moving {direction}')
case Command('look', _):
print('Looking around')
