python-attrs / python-attrs/attrs
Typing problem for validator collections
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Description
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.
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 locating the deep_iterable validator and its type annotations, then compare how list and tuple values are typed for member_validator. The change is complete when mypy accepts the shown example with a list of validators, while the existing tuple behavior remains valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100