Sequences of attrs validators
Open
Nobody has claimed this yet.
bug
topic-attrs
topic-inference
topic-join-v-union
topic-type-context
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
It's only a minor issue, but there was a recent fix on the attrs side to properly handle lists of validators. While code execution works, mypy is still giving a false positive.
To Reproduce
from attrs import define, field
from attrs.validators import deep_iterable, instance_of, min_len
@define
class A:
x: list[str] = field(
validator=deep_iterable(
member_validator=[instance_of(str), min_len(1)],
iterable_validator=[instance_of(list), min_len(1)],
),
)
A(['a', 'b']) # works
Expected Behavior
Should not raise any mypy errors.
Actual Behavior
dbg.py:9: error: Argument "member_validator" to "deep_iterable" has incompatible type "list[function]"; expected "Callable[[Any, Attribute[Never], Never], Any] | Sequence[Callable[[Any, Attribute[Never], Never], Any]]" [arg-type]
dbg.py:10: error: Argument "iterable_validator" to "deep_iterable" has incompatible type "list[function]"; expected "Callable[[Any, Attribute[Never], Never], Any] | Sequence[Callable[[Any, Attribute[Never], Never], Any]] | None" [arg-type]
Your Environment
- Mypy version used: 1.18.2
- Attrs version used: 25.4.0
- Python version used: 3.10
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example with mypy 1.18.2 and inspect the typing for attrs.validators.deep_iterable. Add a regression test covering lists of validators for member_validator and iterable_validator, then verify that mypy reports no errors for the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100