mirror of
https://github.com/python/cpython.git
synced 2025-07-19 01:05:26 +00:00
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:
parent
4c0fc65cd8
commit
784905dbef
5 changed files with 56 additions and 10 deletions
|
@ -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):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue