reportUntypedNamedTuple flags cases where a NamedTuple is defined without explicit type annotations for its fields. This diagnostic helps ensure that all fields in a NamedTuple are properly typed, improving static analysis and code reliability.
- #4163: Ensure consistency in the use of type stubs between Pyright's CLI and Pylance settings.
- #5200: Provide a configuration setting to allow users to customize diagnostic rule severities based on the type checking mode.
- #6300: Exclude unnecessary folders like .venv to improve performance.
- #715: Prefer the
typing.Dictsyntax over the olderdict[t, t]syntax for compatibility across Python versions. - #4367: Ensure that comments in TOML files use correct line endings and do not contain unsupported control characters.
Error:
from collections import namedtuple
Point = namedtuple("Point", ["x", "y"]) # Fields have no type annotationsFix — use typing.NamedTuple with explicit types:
from typing import NamedTuple
class Point(NamedTuple):
x: float
y: floatOr use the functional form with types:
from typing import NamedTuple
Point = NamedTuple("Point", [("x", float), ("y", float)])- Add explicit type annotations to all fields in your
NamedTupledefinitions. - Use the
typing.NamedTupleclass with type annotations for better static analysis. - Exclude unnecessary folders from analysis to improve performance.
- Review the Pyright configuration documentation for details on configuring or disabling this diagnostic.
python.analysis.diagnosticSeverityOverrides— adjust or suppress this diagnosticpython.analysis.typeCheckingMode— controls which diagnostics are enabled by default