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

Performance History

Latest Results

Strip leftover attr.ib() sentinels when these= is passed. these= skips collecting class-body fields, but those attr.ib() objects stayed on the class. Accessing them then returned a private _CountingAttr instead of a missing or real attribute.
gyanu2507:fix/these-leftover-ib-sentinels
11 hours ago
add pr update fragment
RHammond2:feature/eq-validator
14 days 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
21 days 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
21 days 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
21 days ago

Latest Branches

CodSpeed Performance Gauge
0%
Strip leftover attr.ib() sentinels when these= is passed#1614
11 hours ago
7e6bd76
gyanu2507:fix/these-leftover-ib-sentinels
CodSpeed Performance Gauge
0%
7 days ago
e7fe2ab
weed33834:fix/734-kw-only-exception-pickle
CodSpeed Performance Gauge
0%
7 days ago
a440453
cjchanh:expose-cached-properties
© 2026 CodSpeed Technology
Home Terms Privacy Docs