summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_typing.py
diff options
context:
space:
mode:
authorIvan Levkivskyi <levkivskyi@gmail.com>2017-02-24 03:03:28 (GMT)
committerMariatta <Mariatta@users.noreply.github.com>2017-02-24 03:03:28 (GMT)
commitabb3b8ad94d699c8560d94ee9bac9c917b382abe (patch)
tree8032e4fe1bee448b36cfacad7c0f98579a09ca1f /Lib/test/test_typing.py
parent1aceb024172ea3d6f9dd6e90f4fbe63ea1fb054e (diff)
downloadcpython-abb3b8ad94d699c8560d94ee9bac9c917b382abe.zip
cpython-abb3b8ad94d699c8560d94ee9bac9c917b382abe.tar.gz
cpython-abb3b8ad94d699c8560d94ee9bac9c917b382abe.tar.bz2
Update to typing: treat subscripted generics as proxies (#265)
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r--Lib/test/test_typing.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 64d8276..3a82b59 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -674,6 +674,33 @@ class GenericTests(BaseTestCase):
c.bar = 'abc'
self.assertEqual(c.__dict__, {'bar': 'abc'})
+ def test_subscripted_generics_as_proxies(self):
+ T = TypeVar('T')
+ class C(Generic[T]):
+ x = 'def'
+ self.assertEqual(C[int].x, 'def')
+ self.assertEqual(C[C[int]].x, 'def')
+ C[C[int]].x = 'changed'
+ self.assertEqual(C.x, 'changed')
+ self.assertEqual(C[str].x, 'changed')
+ C[List[str]].z = 'new'
+ self.assertEqual(C.z, 'new')
+ self.assertEqual(C[Tuple[int]].z, 'new')
+
+ self.assertEqual(C().x, 'changed')
+ self.assertEqual(C[Tuple[str]]().z, 'new')
+
+ class D(C[T]):
+ pass
+ self.assertEqual(D[int].x, 'changed')
+ self.assertEqual(D.z, 'new')
+ D.z = 'from derived z'
+ D[int].x = 'from derived x'
+ self.assertEqual(C.x, 'changed')
+ self.assertEqual(C[int].z, 'new')
+ self.assertEqual(D.x, 'from derived x')
+ self.assertEqual(D[str].z, 'from derived z')
+
def test_false_subclasses(self):
class MyMapping(MutableMapping[str, str]): pass
self.assertNotIsInstance({}, MyMapping)