@@ -900,10 +900,12 @@ async def coro(self):
900
900
901
901
class DeprecatedCoroTests (BaseTestCase ):
902
902
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 ))
907
909
908
910
@skipUnless (TYPING_3_12_ONLY or TYPING_3_13_0_RC , "inspect.iscoroutinefunction works differently on Python < 3.12" )
909
911
def test_inspect_iscoroutinefunction (self ):
@@ -7282,7 +7284,7 @@ def test_cannot_instantiate_vars(self):
7282
7284
7283
7285
def test_bound_errors (self ):
7284
7286
with self .assertRaises (TypeError ):
7285
- TypeVar ('X' , bound = Union )
7287
+ TypeVar ('X' , bound = Optional )
7286
7288
with self .assertRaises (TypeError ):
7287
7289
TypeVar ('X' , str , float , bound = Employee )
7288
7290
with self .assertRaisesRegex (TypeError ,
@@ -8262,19 +8264,26 @@ def f2(a: "undefined"): # noqa: F821
8262
8264
get_annotations (f2 , format = Format .FORWARDREF ),
8263
8265
{"a" : "undefined" },
8264
8266
)
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
+ )
8266
8272
8267
8273
self .assertEqual (
8268
8274
get_annotations (f1 , format = Format .STRING ),
8269
8275
{"a" : "int" },
8270
8276
)
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
+ )
8272
8281
8273
8282
with self .assertRaises (ValueError ):
8274
8283
get_annotations (f1 , format = 0 )
8275
8284
8276
8285
with self .assertRaises (ValueError ):
8277
- get_annotations (f1 , format = 4 )
8286
+ get_annotations (f1 , format = 42 )
8278
8287
8279
8288
def test_custom_object_with_annotations (self ):
8280
8289
class C :
@@ -8313,10 +8322,17 @@ def foo(a: int, b: str):
8313
8322
foo .__annotations__ = {"a" : "foo" , "b" : "str" }
8314
8323
for format in Format :
8315
8324
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
+ )
8320
8336
8321
8337
self .assertEqual (
8322
8338
get_annotations (foo , eval_str = True , locals = locals ()),
0 commit comments