@@ -367,10 +367,10 @@ def f(): """doc"""
367367def test_compile_top_level_await (self ):
368368"""Test whether code some top level await can be compiled.
369369
370- Make sure it compiles only with the PyCF_ALLOW_TOP_LEVEL_AWAIT flag set,
371- and make sure the generated code object has the CO_COROUTINE flag set in
372- order to execute it with `await eval(.....)` instead of exec, or via a
373- FunctionType.
370+ Make sure it compiles only with the PyCF_ALLOW_TOP_LEVEL_AWAIT flag
371+ set, and make sure the generated code object has the CO_COROUTINE flag
372+ set in order to execute it with `await eval(.....)` instead of exec,
373+ or via a FunctionType.
374374 """
375375
376376# helper function just to check we can run top=level async-for
@@ -379,35 +379,37 @@ async def arange(n):
379379yield i
380380
381381modes = ('single' ,'exec' )
382- code_samples = ['''a = await asyncio.sleep(0, result=1)''' ,
383- '''async for i in arange(1):
384- a = 1''' ,
385- '''async with asyncio.Lock() as l:
386- a = 1''' ]
382+ code_samples = [
383+ '''a = await asyncio.sleep(0, result=1)''' ,
384+ '''async for i in arange(1):
385+ a = 1''' ,
386+ '''async with asyncio.Lock() as l:
387+ a = 1'''
388+ ]
387389policy = maybe_get_event_loop_policy ()
388390try :
389- for mode ,code_sample in product (modes ,code_samples ):
391+ for mode ,code_sample in product (modes ,code_samples ):
390392source = dedent (code_sample )
391- with self .assertRaises (SyntaxError ,msg = f"{ source = } { mode = } " ):
392- compile (source ,'?' ,mode )
393+ with self .assertRaises (
394+ SyntaxError ,msg = f"source={ source } mode={ mode } " ):
395+ compile (source ,'?' ,mode )
393396
394397co = compile (source ,
395398'?' ,
396399mode ,
397400flags = ast .PyCF_ALLOW_TOP_LEVEL_AWAIT )
398401
399402self .assertEqual (co .co_flags & CO_COROUTINE ,CO_COROUTINE ,
400- msg = f"{ source = } { mode = } " )
401-
403+ msg = f"source={ source } mode={ mode } " )
402404
403405# test we can create and advance a function type
404- globals_ = {'asyncio' :asyncio ,'a' :0 ,'arange' :arange }
406+ globals_ = {'asyncio' :asyncio ,'a' :0 ,'arange' :arange }
405407async_f = FunctionType (co ,globals_ )
406408asyncio .run (async_f ())
407409self .assertEqual (globals_ ['a' ],1 )
408410
409411# test we can await-eval,
410- globals_ = {'asyncio' :asyncio ,'a' :0 ,'arange' :arange }
412+ globals_ = {'asyncio' :asyncio ,'a' :0 ,'arange' :arange }
411413asyncio .run (eval (co ,globals_ ))
412414self .assertEqual (globals_ ['a' ],1 )
413415finally :
@@ -416,7 +418,8 @@ async def arange(n):
416418def test_compile_async_generator (self ):
417419"""
418420 With the PyCF_ALLOW_TOP_LEVEL_AWAIT flag added in 3.8, we want to
419- make sure AsyncGenerators are still properly not marked with CO_COROUTINE
421+ make sure AsyncGenerators are still properly not marked with the
422+ CO_COROUTINE flag.
420423 """
421424code = dedent ("""async def ticker():
422425 for i in range(10):
@@ -428,7 +431,6 @@ def test_compile_async_generator(self):
428431exec (co ,glob )
429432self .assertEqual (type (glob ['ticker' ]()),AsyncGeneratorType )
430433
431-
432434def test_delattr (self ):
433435sys .spam = 1
434436delattr (sys ,'spam' )