attrs
attrs copied to clipboard
Python Classes Without Boilerplate
Attrs has nice support for validation and conversion. That same concept could/should be extended to post setattr() phase of attribute updates. This would allow for publish / subscribe systems on...
Here's the usecase: ``` def decrypt_secret(value): return ... @attrs.frozen class Settings: user: str pwd: str = attrs.field(converter=decrypt_secret) sett = Settings(user="name", pwd=) sett.pwd # already decrypted value attrs.evolve(sett, user="name2") ``` This...
This is not a bug per se but more an improvement. From my understanding, converters are passed only the value today. Would it be possible to pass the attribute name...
Recently I wrote a modification to the `attrs.evolve` function that works like this: ```python @attrs.define class Foo: a: int @attrs.define class Bar(Foo): b: str foo = Foo(1) bar = evolve_as(foo,...
This original issue #1004 describes the problem with returning a tuple from `__setstate__`, so #1009 removed it. But once new release was actually cut #1085 reported that this actually broke...
Was looking at the CPython issue tracker and noticed https://github.com/python/cpython/issues/100930 It looks like `attrs` doesn't do this either. I don't know if this is wanted or whether this can work...
Apparently, being able to customize the hashing of individual fields is something interesting for NumPy users: https://stackoverflow.com/q/74975393/476759 --- I guess the idea would be to create a `__hash__` that looks...
Even the birds on the branches nowadays know we do a class switcheroo when defining slot classes. The initial class (the one we throw away) is part of a reference...
Following code: ```python import attrs def decorated(method): def wrapped(self, *args, **kwargs): return method(self, *args, **kwargs) return wrapped @attrs.define() class A: def f(self): pass @attrs.define() class B(A): @decorated def f(self): super().f()...
Provide option in attrs.define to allow users to exclude parameters set to default value from `repr`
# Summary This PR provides functionality in line with #1193. It adds a new parameter to attrs.define to allow users to toggle on/off the ability to create classes that dynamically...