Skip to content

Class helper functions - Support for generic classes #1049

Open
@LukasKrocek

Description

@LukasKrocek

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])```

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypingTyping/stub/Mypy/PyRight related bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions