cpython: f100619e7137 (original) (raw)
--- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -612,8 +612,10 @@ class GenericTests(BaseTestCase): self.assertEqual(repr(typing.Mapping[T, TS][TS, T]), 'typing.Mapping[~TS, ~T]') self.assertEqual(repr(List[Tuple[T, TS]][int, T]), 'typing.List[typing.Tuple[int, ~T]]')
self.assertEqual(repr(List[Tuple[T, T]][List[int]]),[](#l1.7)
'typing.List[typing.Tuple[typing.List[int], typing.List[int]]]')[](#l1.8)
self.assertEqual([](#l1.9)
repr(List[Tuple[T, T]][List[int]]),[](#l1.10)
'typing.List[typing.Tuple[typing.List[int], typing.List[int]]]'[](#l1.11)
)[](#l1.12)
def test_new_repr_bare(self): T = TypeVar('T') @@ -684,8 +686,10 @@ class GenericTests(BaseTestCase): raise NotImplementedError if tp.args: KT, VT = tp.args
return all(isinstance(k, KT) and isinstance(v, VT)[](#l1.20)
for k, v in obj.items())[](#l1.21)
return all([](#l1.22)
isinstance(k, KT) and isinstance(v, VT)[](#l1.23)
for k, v in obj.items()[](#l1.24)
)[](#l1.25) self.assertTrue(naive_dict_check({'x': 1}, typing.Dict[str, int]))[](#l1.26) self.assertFalse(naive_dict_check({1: 'x'}, typing.Dict[str, int]))[](#l1.27) with self.assertRaises(NotImplementedError):[](#l1.28)
@@ -1409,6 +1413,16 @@ class CoolEmployee(NamedTuple): class CoolEmployeeWithDefault(NamedTuple): name: str cool: int = 0 + +class XMeth(NamedTuple):
+ +class XMethBad(NamedTuple):
""" if PY36: @@ -1417,6 +1431,7 @@ else: # fake names for the sake of static analysis ann_module = ann_module2 = ann_module3 = None A = B = CSub = G = CoolEmployee = CoolEmployeeWithDefault = object
gth = get_type_hints @@ -1750,7 +1765,7 @@ class CollectionsAbcTests(BaseTestCase): def test_async_generator(self): ns = {} exec("async def f():\n"
" yield 42\n", globals(), ns)[](#l1.58)
" yield 42\n", globals(), ns)[](#l1.59) g = ns['f']()[](#l1.60) self.assertIsSubclass(type(g), typing.AsyncGenerator)[](#l1.61)
@@ -2039,6 +2054,13 @@ class NonDefaultAfterDefault(NamedTuple) """) @skipUnless(PY36, 'Python 3.6 required')
- def test_annotation_usage_with_methods(self):
self.assertEquals(XMeth(1).double(), 2)[](#l1.68)
self.assertEquals(XMeth(42).x, XMeth(42)[0])[](#l1.69)
self.assertEquals(XMethBad(1)._fields, ('x',))[](#l1.70)
self.assertEquals(XMethBad(1).__annotations__, {'x': int})[](#l1.71)
- @skipUnless(PY36, 'Python 3.6 required') def test_namedtuple_keyword_usage(self): LocalEmployee = NamedTuple("LocalEmployee", name=str, age=int) nick = LocalEmployee('Nick', 25)
--- a/Lib/typing.py +++ b/Lib/typing.py @@ -2000,6 +2000,10 @@ class NamedTupleMeta(type): default_names=', '.join(defaults_dict.keys()))) nm_tpl.new.defaults = tuple(defaults) nm_tpl._field_defaults = defaults_dict
# update from user namespace without overriding special namedtuple attributes[](#l2.7)
for key in ns:[](#l2.8)
if not hasattr(nm_tpl, key):[](#l2.9)
setattr(nm_tpl, key, ns[key])[](#l2.10) return nm_tpl[](#l2.11)