Support my PEP 649 branch by JelleZijlstra · Pull Request #412 · python/typing_extensions · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
24 changes: 18 additions & 6 deletions src/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@
)

ANN_MODULE_SOURCE = '''\
import sys
from typing import List, Optional
from functools import wraps

__annotations__[1] = 2
try:
__annotations__[1] = 2
except NameError:
assert sys.version_info >= (3, 14)

class C:

Expand All @@ -77,8 +81,10 @@ class C:
x: int = 5; y: str = x; f: Tuple[int, int]

class M(type):

__annotations__['123'] = 123
try:
__annotations__['123'] = 123
except NameError:
assert sys.version_info >= (3, 14)
o: type = object

(pars): bool = True
Expand Down Expand Up @@ -1312,7 +1318,10 @@ def tearDownClass(cls):
del sys.modules[modname]

def test_get_type_hints_modules(self):
ann_module_type_hints = {1: 2, 'f': Tuple[int, int], 'x': int, 'y': str}
if sys.version_info >= (3, 14):
ann_module_type_hints = {'f': Tuple[int, int], 'x': int, 'y': str}
else:
ann_module_type_hints = {1: 2, 'f': Tuple[int, int], 'x': int, 'y': str}
self.assertEqual(gth(self.ann_module), ann_module_type_hints)
self.assertEqual(gth(self.ann_module2), {})
self.assertEqual(gth(self.ann_module3), {})
Expand All @@ -1321,7 +1330,10 @@ def test_get_type_hints_classes(self):
self.assertEqual(gth(self.ann_module.C, self.ann_module.__dict__),
{'y': Optional[self.ann_module.C]})
self.assertIsInstance(gth(self.ann_module.j_class), dict)
self.assertEqual(gth(self.ann_module.M), {'123': 123, 'o': type})
if sys.version_info >= (3, 14):
self.assertEqual(gth(self.ann_module.M), {'o': type})
else:
self.assertEqual(gth(self.ann_module.M), {'123': 123, 'o': type})
self.assertEqual(gth(self.ann_module.D),
{'j': str, 'k': str, 'y': Optional[self.ann_module.C]})
self.assertEqual(gth(self.ann_module.Y), {'z': int})
Expand Down Expand Up @@ -2994,7 +3006,7 @@ def meth(self): pass # noqa: B027

acceptable_extra_attrs = {
'_is_protocol', '_is_runtime_protocol', '__parameters__',
'__init__', '__annotations__', '__subclasshook__',
'__init__', '__annotations__', '__subclasshook__', '__annotate__'
}
self.assertLessEqual(vars(NonP).keys(), vars(C).keys() | acceptable_extra_attrs)
self.assertLessEqual(
Expand Down
16 changes: 14 additions & 2 deletions src/typing_extensions.py