attrs
attrs copied to clipboard
Python Classes Without Boilerplate
@hynek @chadrik I've tried following [this](https://github.com/python-attrs/attrs/issues/104) and [other](https://github.com/python-attrs/attrs/pull/277) threads and reading the current docs, but can't see if/how one best produces any documentation directly from the `attr.ib()` definitions. If it...
Suppose we use attrs instances to represent graphs: ``` python >>> @attr.s ... class Node: ... val = attr.ib() ... linked_node = attr.ib(default=None) ... >>> n = Node(1) >>> attr.asdict(n)...
Consider this code: ```python import attr @attr.s(auto_attribs=True, kw_only=True) class A: foo: str @attr.s(auto_attribs=True, kw_only=True) class B(A): foo = "bar" b = B() ``` When compiled, this fails with: ``` TypeError:...
all attrs does is remove the leading "_" which is a bit unfortunate ```python import attr @attr.s class Breakfast: __spam = attr.ib() __eggs = attr.ib() @classmethod def create(cls): return cls(Breakfast__spam=1,...
Extracted from https://github.com/python-attrs/attrs/issues/408#issuecomment-514375369 > On the other side of this, what about making a namespace that actually _is_ intentionally similar to PEP 557 `dataclasses` and `fields`, and just has a...
`pyright` is adding support for `attrs` classes in static type checking through a source-level extension mechanism called [dataclass transforms](https://github.com/microsoft/pyright/blob/master/specs/dataclass_transforms.md). This will provide support the strict-subset of `attrs` class semantics implemented...
It would be a cool feature to have properties that participate in asdict method. ```python @attr.s class SomeClass: @attr.property(asdict=True) def some_dynamic_attr(self): return True print(asdict(SomeClass())) >> {'some_dynamic_attr': True} ```
With [PEP 570](https://www.python.org/dev/peps/pep-0570/), positional-only parameters were introduced. Similarly to keyword-only parameters, I would like to see these as an option for attrs. One thing that makes them "special" is that...
@attr.s(these=dict(a=attr.ib())) class test: b: int = attr.ib(default=0) c = test(5) print(c.b) This fails even if passing `auto_attribs=True`, albeit in a slightly different way. The obvious workaround is to only put...
Hi again! As we know, `hash(x)` in python yields different values across different interpreter sessions for security. It turns out that I am using attrs in all of my class...