mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-40182: Remove the _field_types attribute of the NamedTuple class (GH-19368)
This commit is contained in:
parent
1b21573a89
commit
6fed3c8540
5 changed files with 16 additions and 12 deletions
|
@ -1705,9 +1705,7 @@ def _make_nmtuple(name, types):
|
|||
msg = "NamedTuple('Name', [(f0, t0), (f1, t1), ...]); each t must be a type"
|
||||
types = [(n, _type_check(t, msg)) for n, t in types]
|
||||
nm_tpl = collections.namedtuple(name, [n for n, t in types])
|
||||
# Prior to PEP 526, only _field_types attribute was assigned.
|
||||
# Now __annotations__ are used and _field_types is deprecated (remove in 3.9)
|
||||
nm_tpl.__annotations__ = nm_tpl._field_types = dict(types)
|
||||
nm_tpl.__annotations__ = dict(types)
|
||||
try:
|
||||
nm_tpl.__module__ = sys._getframe(2).f_globals.get('__name__', '__main__')
|
||||
except (AttributeError, ValueError):
|
||||
|
@ -1717,7 +1715,7 @@ def _make_nmtuple(name, types):
|
|||
|
||||
# attributes prohibited to set in NamedTuple class syntax
|
||||
_prohibited = {'__new__', '__init__', '__slots__', '__getnewargs__',
|
||||
'_fields', '_field_defaults', '_field_types',
|
||||
'_fields', '_field_defaults',
|
||||
'_make', '_replace', '_asdict', '_source'}
|
||||
|
||||
_special = {'__module__', '__name__', '__annotations__'}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue