Skip to content

Commit 32dde8e

Browse files
committed
Fix test failures on Python 3.14
1 parent 304f5cb commit 32dde8e

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/test_typing_extensions.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -882,10 +882,12 @@ async def coro(self):
882882

883883
class DeprecatedCoroTests(BaseTestCase):
884884
def test_asyncio_iscoroutinefunction(self):
885-
self.assertFalse(asyncio.coroutines.iscoroutinefunction(func))
886-
self.assertFalse(asyncio.coroutines.iscoroutinefunction(Cls.func))
887-
self.assertTrue(asyncio.coroutines.iscoroutinefunction(coro))
888-
self.assertTrue(asyncio.coroutines.iscoroutinefunction(Cls.coro))
885+
with warnings.catch_warnings():
886+
warnings.simplefilter("ignore", DeprecationWarning)
887+
self.assertFalse(asyncio.coroutines.iscoroutinefunction(func))
888+
self.assertFalse(asyncio.coroutines.iscoroutinefunction(Cls.func))
889+
self.assertTrue(asyncio.coroutines.iscoroutinefunction(coro))
890+
self.assertTrue(asyncio.coroutines.iscoroutinefunction(Cls.coro))
889891

890892
@skipUnless(TYPING_3_12_ONLY or TYPING_3_13_0_RC, "inspect.iscoroutinefunction works differently on Python < 3.12")
891893
def test_inspect_iscoroutinefunction(self):
@@ -7209,7 +7211,7 @@ def test_cannot_instantiate_vars(self):
72097211

72107212
def test_bound_errors(self):
72117213
with self.assertRaises(TypeError):
7212-
TypeVar('X', bound=Union)
7214+
TypeVar('X', bound=Optional)
72137215
with self.assertRaises(TypeError):
72147216
TypeVar('X', str, float, bound=Employee)
72157217
with self.assertRaisesRegex(TypeError,
@@ -8190,19 +8192,25 @@ def f2(a: "undefined"): # noqa: F821
81908192
get_annotations(f2, format=Format.FORWARDREF),
81918193
{"a": "undefined"},
81928194
)
8193-
self.assertEqual(get_annotations(f2, format=2), {"a": "undefined"})
8195+
self.assertEqual(
8196+
get_annotations(f2, format=Format.FORWARDREF.value),
8197+
{"a": "undefined"},
8198+
)
81948199

81958200
self.assertEqual(
81968201
get_annotations(f1, format=Format.STRING),
81978202
{"a": "int"},
81988203
)
8199-
self.assertEqual(get_annotations(f1, format=3), {"a": "int"})
8204+
self.assertEqual(
8205+
get_annotations(f1, format=Format.STRING.value),
8206+
{"a": "int"},
8207+
)
82008208

82018209
with self.assertRaises(ValueError):
82028210
get_annotations(f1, format=0)
82038211

82048212
with self.assertRaises(ValueError):
8205-
get_annotations(f1, format=4)
8213+
get_annotations(f1, format=42)
82068214

82078215
def test_custom_object_with_annotations(self):
82088216
class C:
@@ -8240,6 +8248,8 @@ def foo(a: int, b: str):
82408248

82418249
foo.__annotations__ = {"a": "foo", "b": "str"}
82428250
for format in Format:
8251+
if format is Format.VALUE_WITH_FAKE_GLOBALS:
8252+
continue
82438253
with self.subTest(format=format):
82448254
self.assertEqual(
82458255
get_annotations(foo, format=format),

src/typing_extensions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4139,8 +4139,9 @@ def __eq__(self, other: object) -> bool:
41394139

41404140
class Format(enum.IntEnum):
41414141
VALUE = 1
4142-
FORWARDREF = 2
4143-
STRING = 3
4142+
VALUE_WITH_FAKE_GLOBALS = 2
4143+
FORWARDREF = 3
4144+
STRING = 4
41444145

41454146

41464147
if _PEP_649_OR_749_IMPLEMENTED:
@@ -4184,6 +4185,8 @@ def get_annotations(obj, *, globals=None, locals=None, eval_str=False,
41844185
41854186
"""
41864187
format = Format(format)
4188+
if format is Format.VALUE_WITH_FAKE_GLOBALS:
4189+
raise ValueError("The VALUE_WITH_FAKE_GLOBALS format is for internal use only")
41874190

41884191
if eval_str and format is not Format.VALUE:
41894192
raise ValueError("eval_str=True is only supported with format=Format.VALUE")

0 commit comments

Comments
 (0)