namedtuples_type_compat
error
NamedTuple-to-tuple type incompatibility
When a NamedTuple instance is assigned to a variable annotated with a fixed-length tuple... type, Basilisk verifies:
1. The element count matches the number of fields in the NamedTuple. 2. Each element type in the tuple annotation is compatible with the corresponding NamedTuple field type (with covariance).
class Point(NamedTuple):
x: int
y: int
units: str = "meters"
p = Point(x=1, y=2, units="inches")
v1: tuple[int, int, str] = p # OK
v2: tuple[int, int] = p # E -- too few elements (2 vs 3 fields)
v3: tuple[int, str, str] = p # E -- incompatible element type
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
namedtuples_type_compat 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_type_compat