attrs icon indicating copy to clipboard operation
attrs copied to clipboard

Typing problem for validator collections

Open AdrianSosic opened this issue 1 year ago • 0 comments

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.

AdrianSosic avatar Feb 21 '24 15:02 AdrianSosic