Skip to content

Commit fe12191

Browse files
Fix test failures on Python 3.14 (#566)
1 parent f02b99d commit fe12191

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

src/test_typing_extensions.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -900,10 +900,12 @@ async def coro(self):
900900

901901
class DeprecatedCoroTests(BaseTestCase):
902902
def test_asyncio_iscoroutinefunction(self):
903-
self.assertFalse(asyncio.coroutines.iscoroutinefunction(func))
904-
self.assertFalse(asyncio.coroutines.iscoroutinefunction(Cls.func))
905-
self.assertTrue(asyncio.coroutines.iscoroutinefunction(coro))
906-
self.assertTrue(asyncio.coroutines.iscoroutinefunction(Cls.coro))
903+
with warnings.catch_warnings():
904+
warnings.simplefilter("ignore", DeprecationWarning)
905+
self.assertFalse(asyncio.coroutines.iscoroutinefunction(func))
906+
self.assertFalse(asyncio.coroutines.iscoroutinefunction(Cls.func))
907+
self.assertTrue(asyncio.coroutines.iscoroutinefunction(coro))
908+
self.assertTrue(asyncio.coroutines.iscoroutinefunction(Cls.coro))
907909

908910
@skipUnless(TYPING_3_12_ONLY or TYPING_3_13_0_RC, "inspect.iscoroutinefunction works differently on Python < 3.12")
909911
def test_inspect_iscoroutinefunction(self):
@@ -7282,7 +7284,7 @@ def test_cannot_instantiate_vars(self):
72827284

72837285
def test_bound_errors(self):
72847286
with self.assertRaises(TypeError):
7285-
TypeVar('X', bound=Union)
7287+
TypeVar('X', bound=Optional)
72867288
with self.assertRaises(TypeError):
72877289
TypeVar('X', str, float, bound=Employee)
72887290
with self.assertRaisesRegex(TypeError,
@@ -8262,19 +8264,26 @@ def f2(a: "undefined"): # noqa: F821
82628264
get_annotations(f2, format=Format.FORWARDREF),
82638265
{"a": "undefined"},
82648266
)
8265-
self.assertEqual(get_annotations(f2, format=2), {"a": "undefined"})
8267+
# Test that the raw int also works
8268+
self.assertEqual(
8269+
get_annotations(f2, format=Format.FORWARDREF.value),
8270+
{"a": "undefined"},
8271+
)
82668272

82678273
self.assertEqual(
82688274
get_annotations(f1, format=Format.STRING),
82698275
{"a": "int"},
82708276
)
8271-
self.assertEqual(get_annotations(f1, format=3), {"a": "int"})
8277+
self.assertEqual(
8278+
get_annotations(f1, format=Format.STRING.value),
8279+
{"a": "int"},
8280+
)
82728281

82738282
with self.assertRaises(ValueError):
82748283
get_annotations(f1, format=0)
82758284

82768285
with self.assertRaises(ValueError):
8277-
get_annotations(f1, format=4)
8286+
get_annotations(f1, format=42)
82788287

82798288
def test_custom_object_with_annotations(self):
82808289
class C:
@@ -8313,10 +8322,17 @@ def foo(a: int, b: str):
83138322
foo.__annotations__ = {"a": "foo", "b": "str"}
83148323
for format in Format:
83158324
with self.subTest(format=format):
8316-
self.assertEqual(
8317-
get_annotations(foo, format=format),
8318-
{"a": "foo", "b": "str"},
8319-
)
8325+
if format is Format.VALUE_WITH_FAKE_GLOBALS:
8326+
with self.assertRaisesRegex(
8327+
ValueError,
8328+
"The VALUE_WITH_FAKE_GLOBALS format is for internal use only"
8329+
):
8330+
get_annotations(foo, format=format)
8331+
else:
8332+
self.assertEqual(
8333+
get_annotations(foo, format=format),
8334+
{"a": "foo", "b": "str"},
8335+
)
83208336

83218337
self.assertEqual(
83228338
get_annotations(foo, eval_str=True, locals=locals()),

src/typing_extensions.py

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

37903790
class Format(enum.IntEnum):
37913791
VALUE = 1
3792-
FORWARDREF = 2
3793-
STRING = 3
3792+
VALUE_WITH_FAKE_GLOBALS = 2
3793+
FORWARDREF = 3
3794+
STRING = 4
37943795

37953796

37963797
if _PEP_649_OR_749_IMPLEMENTED:
@@ -3834,6 +3835,10 @@ def get_annotations(obj, *, globals=None, locals=None, eval_str=False,
38343835
38353836
"""
38363837
format = Format(format)
3838+
if format is Format.VALUE_WITH_FAKE_GLOBALS:
3839+
raise ValueError(
3840+
"The VALUE_WITH_FAKE_GLOBALS format is for internal use only"
3841+
)
38373842

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

0 commit comments

Comments
 (0)