Skip to content

collections-named-tuple (PYI024)#

Derived from the flake8-pyi linter.

What it does#

Checks for uses of collections.namedtuple in stub files.

Why is this bad?#

typing.NamedTuple is the "typed version" of collections.namedtuple.

The class generated by subclassing typing.NamedTuple is equivalent to collections.namedtuple, with the exception that typing.NamedTuple includes an __annotations__ attribute, which allows type checkers to infer the types of the fields.

Example#

from collections import namedtuple


person = namedtuple("Person", ["name", "age"])

Use instead:

from typing import NamedTuple


class Person(NamedTuple):
    name: str
    age: int