Skip to content

Mypy false positive for union validator #1336

@AdrianSosic

Description

@AdrianSosic

Not sure if this is a duplicate but I couldn't find the problem in the open issues. If I overlooked it, please close, of course.

from attrs import define, field
from attrs.validators import instance_of

LeTypeAlias = int | str


@define
class LeClass:
    x: LeTypeAlias = field(validator=instance_of(LeTypeAlias))

Works perfectly but mypy complains about:

error: No overload variant of "instance_of" matches argument type "UnionType[int, str]"  [call-overload]

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