python-attrs / attrs

Python Classes Without Boilerplate
https://www.attrs.org/
MIT License
5.28k stars 369 forks source link

Mypy false positive for union validator #1336

Open AdrianSosic opened 2 months ago

AdrianSosic commented 2 months ago

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]
hynek commented 2 months ago

That doesn’t sound familiar and should be easy to fix. 🤞