@@ -358,57 +358,110 @@ async def bar():
358358 with self .subTest (code = code ), self .assertRaises (SyntaxError ):
359359 compile (code , "<test>" , "exec" )
360360
361- def test_goodsyntax_1 (self ):
362- # Tests for issue 24619
361+ def test_badsyntax_2 (self ):
362+ samples = [
363+ """def foo():
364+ await = 1
365+ """ ,
366+
367+ """class Bar:
368+ def async(): pass
369+ """ ,
363370
364- def foo (await ):
365- async def foo (): pass
366- async def foo ():
371+ """class Bar:
372+ async = 1
373+ """ ,
374+
375+ """class async:
367376 pass
368- return await + 1
369- self .assertEqual (foo (10 ), 11 )
377+ """ ,
370378
371- def foo (await ):
372- async def foo (): pass
373- async def foo (): pass
374- return await + 2
375- self .assertEqual (foo (20 ), 22 )
379+ """class await:
380+ pass
381+ """ ,
376382
377- def foo ( await ):
383+ """import math as await""" ,
378384
379- async def foo (): pass
385+ """def async():
386+ pass""" ,
380387
381- async def foo (): pass
388+ """def foo(*, await=1):
389+ pass"""
382390
383- return await + 2
384- self .assertEqual (foo (20 ), 22 )
391+ """async = 1""" ,
385392
386- def foo (await ):
387- """spam"""
388- async def foo (): \
389- pass
390- # 123
391- async def foo (): pass
392- # 456
393- return await + 2
394- self .assertEqual (foo (20 ), 22 )
395-
396- def foo (await ):
397- def foo (): pass
398- def foo (): pass
399- async def bar (): return await_
400- await_ = await
401- try :
402- bar ().send (None )
403- except StopIteration as ex :
404- return ex .args [0 ]
405- self .assertEqual (foo (42 ), 42 )
393+ """print(await=1)"""
394+ ]
406395
407- async def f ():
408- async def g (): pass
409- await z
410- await = 1
411- self .assertTrue (inspect .iscoroutinefunction (f ))
396+ for code in samples :
397+ with self .subTest (code = code ), self .assertWarnsRegex (
398+ DeprecationWarning ,
399+ "'await' will become reserved keywords" ):
400+ compile (code , "<test>" , "exec" )
401+
402+ def test_badsyntax_3 (self ):
403+ with self .assertRaises (DeprecationWarning ):
404+ with warnings .catch_warnings ():
405+ warnings .simplefilter ("error" )
406+ compile ("async = 1" , "<test>" , "exec" )
407+
408+ def test_goodsyntax_1 (self ):
409+ # Tests for issue 24619
410+
411+ samples = [
412+ '''def foo(await):
413+ async def foo(): pass
414+ async def foo():
415+ pass
416+ return await + 1
417+ ''' ,
418+
419+ '''def foo(await):
420+ async def foo(): pass
421+ async def foo(): pass
422+ return await + 1
423+ ''' ,
424+
425+ '''def foo(await):
426+
427+ async def foo(): pass
428+
429+ async def foo(): pass
430+
431+ return await + 1
432+ ''' ,
433+
434+ '''def foo(await):
435+ """spam"""
436+ async def foo(): \
437+ pass
438+ # 123
439+ async def foo(): pass
440+ # 456
441+ return await + 1
442+ ''' ,
443+
444+ '''def foo(await):
445+ def foo(): pass
446+ def foo(): pass
447+ async def bar(): return await_
448+ await_ = await
449+ try:
450+ bar().send(None)
451+ except StopIteration as ex:
452+ return ex.args[0] + 1
453+ '''
454+ ]
455+
456+ for code in samples :
457+ with self .subTest (code = code ):
458+ loc = {}
459+
460+ with warnings .catch_warnings ():
461+ warnings .simplefilter ("ignore" )
462+ exec (code , loc , loc )
463+
464+ self .assertEqual (loc ['foo' ](10 ), 11 )
412465
413466
414467class TokenizerRegrTest (unittest .TestCase ):
0 commit comments