attrs icon indicating copy to clipboard operation
attrs copied to clipboard

Python Classes Without Boilerplate

Results 198 attrs issues
Sort by recently updated
recently updated
newest added

A user might want to use attributes from an already `@define`d class to populate a new attrs class. However, `_ClassBuilder` expects all given attributes to be instances of `_CountingAttr` instead...

The documentation says: >If `__attrs_pre_init__` takes more than the `self` argument, the attrs-generated `__init__` will call it with the same arguments it received itself. However, if those attributes are specified...

Consider the following ``` @attrs.define class A: @functools.cached_property def x(self) -> list[int]: print('caching') return list(range(5)) ``` The following behavior is expected: ``` In []: attrs.__version__ Out[]: '25.3.0' In []: a...

I don't really know why CI doesn't reproduce this, but I'm seeing it both with PyPy3.10 and PyPy3.11, 7.3.19 and latest nightly. ```pytb $ tox -e pypy310-tests,pypy311-tests .pkg: _optional_hooks> python...

Unless I am mistaken, one cannot use `attrs.fields` on a attrs class object, unlike `attrs.has`. The workaround is simple, either `attrs.fields(type(obj))` or `obj.__attrs_attrs__`. It would be nice to be able...

Feature

Consider this MRE ```python from attrs import define, fields @define class A: foo: int bar: float f = fields(A) ``` ```py print(f.foo) ``` ``` Attribute(name='foo', default=NOTHING, validator=None, repr=True, eq=True, eq_key=None,...

Typing

Is it possible to combine two (or more) class declarations into one? This should be similar to multiple inheritance I guess, but should work with slots. For example: ``` @define...

Feature

Is it possible to add the `runtime_checkable` decorator to `AttrsInstance` protocol? https://github.com/python-attrs/attrs/blob/598494a618410490cfbe0c896b7a544f6d23e0d9/src/attr/__init__.py#L37-L38 In my project, I am working on a decorator that automates converting a dict into an `AttrsInstance`. To...

Feature