Skip to content

Use of AttrsInstance protocol is incompatible with type checkers other than mypy #996

Open
@layday

Description

@layday

The latest release introduced the AttrsInstance protocol with one attribute, __attrs_attrs__, which replaced Any in the signature of various core functions. The __attrs_attrs__ attribute is "injected" by the attrs mypy plug-in; other type checkers have no knowledge of this attribute and adding attributes to the type definition of a dataclass-like class is not supported by dataclass_transform. Therefore, functions such as fields and asdict generate type errors by default in all type checkers other than mypy. I am not familiar with mypy plug-ins but I assume one alternative would be to remove the attribute from the protocol definition and inject it dynamically from the plug-in, the way it's done for the attrs class. Longer term, an extension to dataclass_transform could be sought.

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