Skip to content

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.

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.

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.

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.

Bad

`class Job(FrozenModel): tags: tuple[str, ...] = ()` fixes a concrete representation without
proving that tuple identity matters.
Good

tags: 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.

  • 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