bpo-45166: fixes get_type_hints failure on Final (GH-28279)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
This commit is contained in:
Nikita Sobolev 2021-09-25 11:56:22 +03:00 committed by GitHub
parent 4c0fc65cd8
commit 784905dbef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 10 deletions

View file

@ -2975,7 +2975,7 @@ else:
# Definitions needed for features introduced in Python 3.6
from test import ann_module, ann_module2, ann_module3
from test import ann_module, ann_module2, ann_module3, ann_module5, ann_module6
from typing import AsyncContextManager
class A:
@ -3339,6 +3339,22 @@ class GetUtilitiesTestCase(TestCase):
(Concatenate[int, P], int))
self.assertEqual(get_args(list | str), (list, str))
def test_forward_ref_and_final(self):
# https://bugs.python.org/issue45166
hints = get_type_hints(ann_module5)
self.assertEqual(hints, {'name': Final[str]})
hints = get_type_hints(ann_module5.MyClass)
self.assertEqual(hints, {'value': Final})
def test_top_level_class_var(self):
# https://bugs.python.org/issue45166
with self.assertRaisesRegex(
TypeError,
r'typing.ClassVar\[int\] is not valid as type argument',
):
get_type_hints(ann_module6)
class CollectionsAbcTests(BaseTestCase):