attrs
attrs copied to clipboard
Python Classes Without Boilerplate
Inheritance breaks `mypy` type checking with optional attributes if `Generic`s are involved: ``` from typing import Generic, Optional, TypeVar import attr T = TypeVar("T") @attr.mutable() class Parent(Generic[T]): # Removing `Generic`...
The is related to #593/#760. Because #760 populates the generated `__init__` method's globals at the time that the class is created, new globals aren't visible to `get_type_hints` by default. Example...
**Describe the bug** Using `pyright` for type checking produces the following errors: ```python from attrs import define @define class A: foo: int bar: str = "baz" @define class B(A): zoo:...
Mixed inheritance between slotted and non-slotted classes seems to lead to some issues when object are copied for parallelization. The following code example does not work and raises: `AttributeError: 'Child'...
Same context [here](https://stackoverflow.com/questions/73312870/correct-mro-order-attrs-object-cant-find-abstract-property) The following runs fine: ``` from abc import ABC, abstractmethod import attr class A(ABC): @abstractmethod def prop(self): pass def foo(self): print(self.prop()) class B: def prop(self): return 5...
I've been asked to add `unsafe_hash` as an alias for `hash` **at class level** for PEP 618 (data class transforms). I'm not enthusiastic about the lack of symmetry between class-level...
Setup ```python from attrs import ( Factory, field, frozen, validators, ) ``` Simple validation, all good: ```python @frozen class Foo: text: str = field(validator=validators.instance_of(str)) Foo(1) # TypeError: ("'text' must be...
@hynek thanks for the work on `attrs`! Ideally, I'd only like a field to appear in a class' *repr* if that field is set to a non-default value. An example...
`dataclass` dataclasses handle descriptor fields differently from other fields, so the descriptor type is not lost when assigning: https://docs.python.org/3/library/dataclasses.html#descriptor-typed-fields This does not work in `attrs`, it's a pity because it...
I wish I could write: `validator=attrs.validators.instance_of(typing.Optional[list[int]])` instead of: ``` validator=attrs.validators.instance_of( attrs.validators.optional(attrs.validators.deep_iterable(int))) ``` It is easier to read and there is not need to use another differente way to express a...