-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationhelp wantedContributions especially welcomeContributions especially welcome
Description
Summary
From the doc:
from collections import namedtuple
person = namedtuple("Person", ["name", "age"])Use instead:
from typing import NamedTuple
class Person(NamedTuple):
name: str
age: intBut that's not equivalent! Since the variable name person differs from the class name Person.
For this to be equivalent:
from collections import namedtuple
person = namedtuple("Person", ["name", "age"])
Rect = namedtuple("Rect", ["x", "y"])This would be used:
from typing import NamedTuple
class person(NamedTuple):
__name__ = "Person"
name: str
age: int
class Rect(NamedTuple):
x: int
y: intor
from typing import NamedTuple
class Person(NamedTuple):
name: str
age: int
person = Person # old name
class Rect(NamedTuple):
x: int
y: intI wouldn't recommend that usage. But backwards compatibility is important in libraries, where NamedTuples matter more.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationhelp wantedContributions especially welcomeContributions especially welcome