Skip to content

TYP use typed version of namedtuple #40531

Closed
@MarcoGorelli

Description

@MarcoGorelli

Instead of

OutputKey = collections.namedtuple("OutputKey", ["label", "position"])

we can do

from typing import NamedTuple

class OutputKey(NamedTuple)
    label
    position

The advantage is that like this we can add type hints to the various elements, such as

from typing import NamedTuple

class OutputKey(NamedTuple)
    label: Hashable
    position: int

See https://docs.python.org/3/library/typing.html#typing.NamedTuple for reference

Metadata

Metadata

Assignees

Labels

Typingtype annotations, mypy/pyright type checkinggood first issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions