namedtuples_usage error

NamedTuple usage violations

Detects invalid usage of NamedTuple instances:

1. **Out-of-bounds index access**: p3 on a 3-field NamedTuple (valid: 0..2 or -3..-1). 2. **Attribute assignment**: p.x = 3NamedTuple fields are read-only. 3. **Subscript assignment**: p0 = 3NamedTuple elements are read-only. 4. **Attribute deletion**: del p.xNamedTuple fields cannot be deleted. 5. **Subscript deletion**: del p0NamedTuple elements cannot be deleted. 6. **Wrong-count tuple unpack**: x, y = p when p has 3 fields.

class Point(NamedTuple):
    x: int
    y: int
    units: str = "meters"

p = Point(1, 2)
print(p[3])     # E: out-of-bounds index
print(p[-4])    # E: out-of-bounds negative index
p.x = 3        # E: NamedTuple fields are read-only
p[0] = 3       # E: NamedTuple elements are read-only
del p.x        # E: NamedTuple fields cannot be deleted
del p[0]       # E: NamedTuple elements cannot be deleted
x, y = p       # E: too few values to unpack (expected 3)

How to handle it

Every rule is on by default — strict is the default, not a cage. You can dial namedtuples_usage down per-file or per-path from your editor or pyproject.toml, or fix the code so it type-checks. See the Type System rules and the complete diagnostic reference.

Canonical URL: https://www.basilisk-python.dev/errors/namedtuples_usage