attrs
attrs copied to clipboard
Python Classes Without Boilerplate
Resolving #165 allowed setting the default for an attribute based on other attributes using a decorator like this: ``` @attrs(frozen=True, slots=True) class Foo: bar = attr.ib() moo = attr.ib() @moo.default...
This works as expected: ```python class A: pass class B(A): pass class C(A): pass assert hash(B) != hash(C) assert hash(B()) != hash(C()) =========================== 1 passed in 3.39 seconds =========================== ```...
I'm trying to add some types to some attrs-using code that uses validators. Here's a minimal example of such: ```python from typing import Any, TypeVar from attr import Attribute T...
When I want to `evolve()` an object, I sometimes have to do a bit of boilerplate `copy()`ing: ```python from typing import List import attr @attr.s class Car: model: str =...
In cases where `cache_hash=True`, we can short-circuit equality checks by first comparing hash codes. This can provide a very big speedup for "heavyweight" objects where field equality comparisons can be...
In some cases it is useful to create an new object by copying some of the attributes that are provided by a shared base class. Here is an example ```python...
Using attrs 19.1.0 on Python 3.6.7, ``` python from typing import Any, Iterable, List, Tuple, TypeVar from attr import attrs, attrib T = TypeVar("T") def to_tuple(val: Iterable[T]) -> Tuple[T, ...]:...
When using `attr.`ibute with both `converter` and `default`, wrong expectations is applied on `default` type (with mypy == 0.670). Mypy dev [say](https://github.com/python/mypy/issues/6533) it's an issue in attr stubs. The valid...
Hello @python-attrs, I've been using the `attrs` library for a while and I really like what you guys have built. We've even started using it to teach our students at...
Hi, I think it would be awesome if the default value for Optional types would be set to None. Here is a snippet I hoped would work: ``` import attr...