Avatar for the python-attrs user
python-attrs
attrs
BlogDocsChangelog

Performance History

Latest Results

Add `dataclass_compatible` flag Short of having some [stdlib fields interface](https://discuss.python.org/t/add-a-fields-interface/108364), the de facto standard for marking a class as "some non-opaque class that you can iterate over the fields of" is the presence of `__dataclass_fields__`. One example of this de facto standard (and the motivation for this PR) is in Pydantic. Pydantic will happily use dataclass definitions for (de)serialization, both in the case of nested definitions, and when using `pydantic.TypeAdapter(T)`. The only way it can tell if something is a dataclass is using `dataclasses.is_dataclass`, which itself just checks for the presence of `__dataclass_fields__`. An `attrs` class masquerading as a dataclass via `__dataclass_fields__` works just fine. Using `pydantic.TypeAdapter` at the edges and normal `attrs` in the core application avoids @tinche's concerns around things like: > Is it really necessary to re-validate all your objects while reading > them from a trusted database? that this PR's author [largely agrees with](https://leontrolski.github.io/pydantic-wrong.html). Another example would be a "map over everything" function like the following: ```python def map_[T](o: T, f: Callable[[T], T]) -> T: if isinstance(o, list): return [map_(v, f) for v in o] # ditto for tuple, set, frozenset, dict, then, if has_fields(o): kwargs = {k: map_(getattr(o, field.name), f) for field in dataclasses.fields(o)} return copy.replace(o, **kwargs) return o ``` With `dataclass_compatible=True` set, functions like this will work without having to muck around checking for the installation of `attrs` and using the subtly different `attrs.fields` function.
leontrolski:add-dataclass-compatible
10 hours ago
Add `dataclass_compatible` flag Short of having some [stdlib fields interface](https://discuss.python.org/t/add-a-fields-interface/108364), the de facto standard for marking a class as "some non-opaque class that you can iterate over the fields of" is the presence of `__dataclass_fields__`. One example of this de facto standard (and the motivation for this PR) is in Pydantic. Pydantic will happily use dataclass definitions for (de)serialization, both in the case of nested definitions, and when using `pydantic.TypeAdapter(T)`. The only way it can tell if something is a dataclass is using `dataclasses.is_dataclass`, which itself just checks for the presence of `__dataclass_fields__`. An `attrs` class masquerading as a dataclass via `__dataclass_fields__` works just fine. Using `pydantic.TypeAdapter` at the edges and normal `attrs` in the core application avoids @tinche's concerns around things like: > Is it really necessary to re-validate all your objects while reading > them from a trusted database? that this PR's author [largely agrees with](https://leontrolski.github.io/pydantic-wrong.html). Another example would be a "map over everything" function like the following: ```python def map_[T](o: T, f: Callable[[T], T]) -> T: if isinstance(o, list): return [map_(v, f) for v in o] # ditto for tuple, set, frozenset, dict, then, if has_fields(o): kwargs = {k: map_(getattr(o, field.name), f) for field in dataclasses.fields(o)} return copy.replace(o, **kwargs) return o ``` With `dataclass_compatible=True` set, functions like this will work without having to muck around checking for the installation of `attrs` and using the subtly different `attrs.fields` function.
leontrolski:add-dataclass-compatible
12 hours ago
Add `dataclass_compatible` flag Short of having some [stdlib fields interface](https://discuss.python.org/t/add-a-fields-interface/108364), the de facto standard for marking a class as "some non-opaque class that you can iterate over the fields of" is the presence of `__dataclass_fields__`. One example of this de facto standard (and the motivation for this PR) is in Pydantic. Pydantic will happily use dataclass definitions for (de)serialization, both in the case of nested definitions, and when using `pydantic.TypeAdapter(T)`. The only way it can tell if something is a dataclass is using `dataclasses.is_dataclass`, which itself just checks for the presence of `__dataclass_fields__`. An `attrs` class masquerading as a dataclass via `__dataclass_fields__` works just fine. Using `pydantic.TypeAdapter` at the edges and normal `attrs` in the core application avoids @tinche's concerns around things like: > Is it really necessary to re-validate all your objects while reading > them from a trusted database? that this PR's author [largely agrees with](https://leontrolski.github.io/pydantic-wrong.html). Another example would be a "map over everything" function like the following: ```python def map_[T](o: T, f: Callable[[T], T]) -> T: if isinstance(o, list): return [map_(v, f) for v in o] # ditto for tuple, set, frozenset, dict, then, if has_fields(o): kwargs = {k: map_(getattr(o, field.name), f) for field in dataclasses.fields(o)} return copy.replace(o, **kwargs) return o ``` With `dataclass_compatible=True` set, functions like this will work without having to muck around checking for the installation of `attrs` and using the subtly different `attrs.fields` function.
leontrolski:add-dataclass-compatible
12 hours ago
Add `dataclass_compatible` flag Short of having some [stdlib fields interface](https://discuss.python.org/t/add-a-fields-interface/108364), the de facto standard for marking a class as "some non-opaque class that you can iterate over the fields of" is the presence of `__dataclass_fields__`. One example of this de facto standard (and the motivation for this PR) is in Pydantic. Pydantic will happily use dataclass definitions for (de)serialization, both in the case of nested definitions, and when using `pydantic.TypeAdapter(T)`. The only way it can tell if something is a dataclass is using `dataclasses.is_dataclass`, which itself just checks for the presence of `__dataclass_fields__`. An `attrs` class masquerading as a dataclass via `__dataclass_fields__` works just fine. Using `pydantic.TypeAdapter` at the edges and normal `attrs` in the core application avoids @tinche's concerns around things like: > Is it really necessary to re-validate all your objects while reading > them from a trusted database? that this PR's author [largely agrees with](https://leontrolski.github.io/pydantic-wrong.html). Another example would be a "map over everything" function like the following: ```python def map_[T](o: T, f: Callable[[T], T]) -> T: if isinstance(o, list): return [map_(v, f) for v in o] # ditto for tuple, set, frozenset, dict, then, if has_fields(o): kwargs = {k: map_(getattr(o, field.name), f) for field in dataclasses.fields(o)} return copy.replace(o, **kwargs) return o ``` With `dataclass_compatible=True` set, functions like this will work without having to muck around checking for the installation of `attrs` and using the subtly different `attrs.fields` function.
leontrolski:add-dataclass-compatible
13 hours ago
Add tox to lockfile
lock-tox
3 days ago

Latest Branches

CodSpeed Performance Gauge
0%
Add `dataclass_compatible` flag#1610
13 hours ago
835b55d
leontrolski:add-dataclass-compatible
CodSpeed Performance Gauge
0%
Add tox to lockfile#1608
3 days ago
51e59e1
lock-tox
CodSpeed Performance Gauge
0%
Fix asdict/astuple filters to match by identity instead of equality (#864)#1607
4 days ago
3351d14
rudrakumar07:fix-asdict-filter-identity
© 2026 CodSpeed Technology
Home Terms Privacy Docs