attrs
attrs copied to clipboard
Class helper functions - Support for generic classes
I noticed that functions like attr.has, attr.fields, attr.fields_dict doesn't work as i expected when i pass in class with generic type defined:
from attr import frozen, evolve, mutable, has, fields, fields_dict, Attribute
T = TypeVar("T")
@frozen
class A(Generic[T]):
a: int
b: T
has(A) => True
has(A[str]) => False (should be True)
fields(A) => Sequence[Attribute]
fields(A[str]) => TypeError: Passed object must be a class (should be Sequence[Attribute])
fields_dict(A) => Mapping[str, Attribute]
fields(A[str]) => TypeError: Passed object must be a class (should be Mapping[str, Attribute])```
Will be taking a look at this soon.
+1
This is quite annoying when I'm using cattrs' hook factories... e.g. the snake_case to camelCase cattrs example doesn't work with generic classes
first support has been merged as part of #1079