[New-bugs-announce] [issue36321] Fix misspelled attribute name in namedtuple()

Raymond Hettinger report at bugs.python.org
Sat Mar 16 16:21:03 EDT 2019


New submission from Raymond Hettinger <raymond.hettinger at gmail.com>:

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().

----------
assignee: rhettinger
components: Library (Lib)
messages: 338096
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Fix misspelled attribute name in namedtuple()
type: behavior
versions: Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36321>
_______________________________________


More information about the New-bugs-announce mailing list