python-attrs / attrs

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

Typing problem for validator collections #1244

Open AdrianSosic opened 9 months ago

AdrianSosic commented 9 months ago

This is a copy of the second issue collected in https://github.com/python-attrs/attrs/issues/1206 to enable separate tracking of the bug.

The issue

Consider the following piece of code:

@define
class A:
    x: List[str] = field(
        validator=deep_iterable(
            member_validator=[instance_of(str), min_len(1)],
            iterable_validator=and_(instance_of(list), min_len(1)),
        ),
    )

When a list of validators is passed for member_validator, mypy complains about the type, as already pointed out in https://github.com/python-attrs/attrs/issues/1197. However, when a tuple is used instead, mypy is happy.