-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-attrstopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotationstopic-join-v-unionUsing join vs. using unionsUsing join vs. using unionstopic-type-contextType context / bidirectional inferenceType context / bidirectional inference
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
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-attrstopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotationstopic-join-v-unionUsing join vs. using unionsUsing join vs. using unionstopic-type-contextType context / bidirectional inferenceType context / bidirectional inference