The attribute name, '_fields_defaults' was misspelled and should have been ''_field_defaults'. The namedtuple documentation uses both spellings. The typing.NamedTuple class consistently uses the latter spelling. The intent was the both would be spelled the same way.
>>> from typing import NamedTuple
>>> class Employee(NamedTuple):
name: str
id: int = 3
>>> Employee._field_defaults
{'id': 3}
>>> from collections import namedtuple
>>> Employee = namedtuple('Employee', ['name', 'id'], defaults=[3])
>>> Employee._fields_defaults
{'id': 3}
Since 3.7 API is already released, it may be reasonable to provide both spellings for namedtuple().
New changeset bedfbc7 by Raymond Hettinger (Miss Islington (bot)) in branch '3.7': bpo-36321: Fix misspelled attribute in namedtuple() (GH-12375) (GH-12395) bedfbc7
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: