summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_typing.py
diff options
context:
space:
mode:
authorNina Zakharenko <nzakharenko@gmail.com>2018-05-16 16:27:03 (GMT)
committerƁukasz Langa <lukasz@langa.pl>2018-05-16 16:27:03 (GMT)
commit2d2d3b170bdebc085900bfa2a3bc81b5d132d0a8 (patch)
tree9bb1b436a933672212db05b3e9e65b418659764c /Lib/test/test_typing.py
parent8b94b41ab7b12f745dea744e8940631318816935 (diff)
downloadcpython-2d2d3b170bdebc085900bfa2a3bc81b5d132d0a8.zip
cpython-2d2d3b170bdebc085900bfa2a3bc81b5d132d0a8.tar.gz
cpython-2d2d3b170bdebc085900bfa2a3bc81b5d132d0a8.tar.bz2
Fix ClassVar as string fails when getting type hints (GH-6824)
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r--Lib/test/test_typing.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 314716c..be768f1 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -1599,6 +1599,30 @@ class ForwardRefTests(BaseTestCase):
# verify that @no_type_check never affects bases
self.assertEqual(get_type_hints(C.meth), {'x': int})
+ def test_no_type_check_forward_ref_as_string(self):
+ class C:
+ foo: typing.ClassVar[int] = 7
+ class D:
+ foo: ClassVar[int] = 7
+ class E:
+ foo: 'typing.ClassVar[int]' = 7
+ class F:
+ foo: 'ClassVar[int]' = 7
+
+ expected_result = {'foo': typing.ClassVar[int]}
+ for clazz in [C, D, E, F]:
+ self.assertEqual(get_type_hints(clazz), expected_result)
+
+ def test_nested_classvar_fails_forward_ref_check(self):
+ class E:
+ foo: 'typing.ClassVar[typing.ClassVar[int]]' = 7
+ class F:
+ foo: ClassVar['ClassVar[int]'] = 7
+
+ for clazz in [E, F]:
+ with self.assertRaises(TypeError):
+ get_type_hints(clazz)
+
def test_meta_no_type_check(self):
@no_type_check_decorator