diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-04-04 21:43:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-04 21:43:20 (GMT) |
commit | 6fed3c85402c5ca704eb3f3189ca3f5c67a08d19 (patch) | |
tree | 756d989deaee347ca211d42abf124d1817ef8ff3 /Lib | |
parent | 1b21573a89632356737a24302dd64c9eb1457a7b (diff) | |
download | cpython-6fed3c85402c5ca704eb3f3189ca3f5c67a08d19.zip cpython-6fed3c85402c5ca704eb3f3189ca3f5c67a08d19.tar.gz cpython-6fed3c85402c5ca704eb3f3189ca3f5c67a08d19.tar.bz2 |
bpo-40182: Remove the _field_types attribute of the NamedTuple class (GH-19368)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_typing.py | 6 | ||||
-rw-r--r-- | Lib/typing.py | 6 |
2 files changed, 4 insertions, 8 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 3a0edb9..dea09eb 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -3561,7 +3561,6 @@ class NamedTupleTests(BaseTestCase): self.assertEqual(Emp._fields, ('name', 'id')) self.assertEqual(Emp.__annotations__, collections.OrderedDict([('name', str), ('id', int)])) - self.assertIs(Emp._field_types, Emp.__annotations__) def test_namedtuple_pyversion(self): if sys.version_info[:2] < (3, 6): @@ -3581,7 +3580,6 @@ class NamedTupleTests(BaseTestCase): self.assertEqual(CoolEmployee._fields, ('name', 'cool')) self.assertEqual(CoolEmployee.__annotations__, collections.OrderedDict(name=str, cool=int)) - self.assertIs(CoolEmployee._field_types, CoolEmployee.__annotations__) def test_annotation_usage_with_default(self): jelle = CoolEmployeeWithDefault('Jelle') @@ -3594,7 +3592,8 @@ class NamedTupleTests(BaseTestCase): self.assertEqual(CoolEmployeeWithDefault.__name__, 'CoolEmployeeWithDefault') self.assertEqual(CoolEmployeeWithDefault._fields, ('name', 'cool')) - self.assertEqual(CoolEmployeeWithDefault._field_types, dict(name=str, cool=int)) + self.assertEqual(CoolEmployeeWithDefault.__annotations__, + dict(name=str, cool=int)) self.assertEqual(CoolEmployeeWithDefault._field_defaults, dict(cool=0)) with self.assertRaises(TypeError): @@ -3641,7 +3640,6 @@ class XMethBad2(NamedTuple): self.assertEqual(LocalEmployee.__name__, 'LocalEmployee') self.assertEqual(LocalEmployee._fields, ('name', 'age')) self.assertEqual(LocalEmployee.__annotations__, dict(name=str, age=int)) - self.assertIs(LocalEmployee._field_types, LocalEmployee.__annotations__) with self.assertRaises(TypeError): NamedTuple('Name', [('x', int)], y=str) with self.assertRaises(TypeError): diff --git a/Lib/typing.py b/Lib/typing.py index 99355d0..a72003a 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -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__'} |