Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class helper functions - Support for generic classes #1049

Open
LukasKrocek opened this issue Nov 3, 2022 · 3 comments
Open

Class helper functions - Support for generic classes #1049

LukasKrocek opened this issue Nov 3, 2022 · 3 comments
Labels
Typing Typing/stub/Mypy/PyRight related bugs.

Comments

@LukasKrocek
Copy link

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])```
@LukasKrocek LukasKrocek changed the title Attr class helper methods - Support for generic classes Attr class helper functions - Support for generic classes Nov 3, 2022
@LukasKrocek LukasKrocek changed the title Attr class helper functions - Support for generic classes Class helper functions - Support for generic classes Nov 3, 2022
@Tinche
Copy link
Member

Tinche commented Dec 31, 2022

Will be taking a look at this soon.

@fredsensibill
Copy link

+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

@hynek
Copy link
Member

hynek commented Feb 6, 2023

first support has been merged as part of #1079

@hynek hynek added the Typing Typing/stub/Mypy/PyRight related bugs. label Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing Typing/stub/Mypy/PyRight related bugs.
Projects
None yet
Development

No branches or pull requests

4 participants