Skip to content

Sequences of attrs validators #20013

@AdrianSosic

Description

@AdrianSosic

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

No one assigned

    Labels

    bugmypy got something wrongtopic-attrstopic-inferenceWhen to infer types or require explicit annotationstopic-join-v-unionUsing join vs. using unionstopic-type-contextType context / bidirectional inference

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions