Skip to content

no-positional-tuple-record

Fixed tuple return records should use named fields instead of positional slots.

Why

A fixed tuple return makes callers remember positions and lets adjacent values be silently swapped. Named records preserve field meaning across public, private, decorated, method, and test boundaries.

Fix

Return a frozen dataclass or validation model. Use typing.NamedTuple only when an exact tuple protocol is required.

Examples

Before — flagged Public function returns a positional record
app/profile.py
def load_profile() -> tuple[str, int, bool]:
return "Ada", 42, True
After — preferred Public function returns a tuple-compatible named record
app/profile.py
from typing import NamedTuple
class Profile(NamedTuple):
name: str
age: int
active: bool
def load_profile() -> Profile:
return Profile(name="Ada", age=42, active=True)

Formerly: prefer-namedtuple-over-tuple-return