PY-PYDA0007 · variadic_tuple_model_field
Find Pydantic fields that require a homogeneous tuple representation.
This is a deterministic rule for python. Read its implementation.
Definition
Section titled “Definition”Inspect directly declared fields on Pydantic and recognized house model bases. Report a field
when its annotation contains an arbitrary-length homogeneous tuple[T, ...], including the
deprecated typing.Tuple spelling and imported aliases. A model boundary should normally
state the operations or normalized representation it needs rather than require callers to
supply one immutable concrete collection.
Evidence
Section titled “Evidence”Each finding names the model, field, exact annotation, and annotation range. The value is the
number of variadic tuple fields. Fixed heterogeneous tuples such as tuple[int, int] remain
untouched because their positions form a record rather than a general collection.
Exceptions
Section titled “Exceptions”Keep a variadic tuple when tuple identity is itself part of the domain or public serialized
contract. Prefer Sequence[T] when the model should preserve list or tuple input, and
list[T] when validation should normalize input to one mutable representation. Container[T]
expresses membership-only APIs but Pydantic needs an explicit schema adapter or arbitrary-type
policy for it, so it is not an automatic model-field replacement.
Examples
Section titled “Examples”Bad
`class Job(FrozenModel): tags: tuple[str, ...] = ()` fixes a concrete representation withoutproving that tuple identity matters.
Goodtags: Sequence[str] = () preserves accepted sequence inputs. tags: list[str] = [] states
that the validated model owns a normalized list. point: tuple[int, int] remains a fixed-shape
record and is not reported.
References
Section titled “References”- Cites “Pydantic documentation”, tuple and sequence validation. Open reference
- Cites “The Python Standard Library”, sequence abstract base classes. Open reference
- Cites “Python typing specification”, tuple types. Open reference