3.7+ "async with" handling from decompyle3

This commit is contained in:
rocky
2020-02-08 19:48:09 -05:00
parent e1758a8730
commit 8495d208fb
9 changed files with 146 additions and 47 deletions

1
test/.gitignore vendored
View File

@@ -1,2 +1,3 @@
/.coverage /.coverage
/.python-version
/nohup.out /nohup.out

Binary file not shown.

Binary file not shown.

View File

@@ -10,3 +10,14 @@ async def test_enter(self):
x = 1 x = 1
y = 2 y = 2
assert manager is context assert manager is context
# From 3.7.6 test_coroutines.py
# Bug was different form of code for "async with" below
class CoroutineTest():
def test_with_8(self):
CNT = 0
async def foo():
nonlocal CNT
async with CM():
CNT += 1
return

View File

@@ -0,0 +1,55 @@
SKIP_TESTS=(
[test_aepack.py]=1 # it fails on its own
[test_al.py]=1 # it fails on its own
[test_applesingle.py]=1 # it fails on its own
[test_bsddb185.py]=1 # it fails on its own
[test_bsddb3.py]=1 # it fails on its own
[test_bsddb.py]=1 # it fails on its own
[test_cd.py]=1 # it fails on its own
[test_cl.py]=1 # it fails on its own
[test_codecmaps_cn.py]=1 # it fails on its own
[test_codecmaps_hk.py]=1 # it fails on its own
[test_codecmaps_jp.py]=1 # it fails on its own
[test_codecmaps_kr.py]=1 # it fails on its own
[test_codecmaps_tw.py]=1 # it fails on its own
[test_curses.py]=1 # it fails on its own
[test_dbm.py]=1 # it fails on its own
[test_dl.py]=1 # it fails on its own
[test_gdbm.py]=1 # it fails on its own
[test_gl.py]=1 # it fails on its own
[test_imageop.py]=1 # it fails on its own
[test_imgfile.py]=1 # it fails on its own
[test_linuxaudiodev.py]=1 # it fails on its own
[test_macfs.py]=1 # it fails on its own
[test_macostools.py]=1 # it fails on its own
[test_nis.py]=1 # it fails on its own
[test_normalization.py]=1 # it fails on its own
[test_ossaudiodev.py]=1 # it fails on its own
[test_pep277.py]=1 # it fails on its own
[test_plistlib.py]=1 # it fails on its own
[test_rgbimg.py]=1 # it fails on its own
[test_scriptpackages.py]=1 # it fails on its own
[test_socket_ssl.py]=1 # it fails on its own
[test_sunaudiodev.py]=1 # it fails on its own
[test_support.py]=1 # it fails on its own
[test_tcl.py]=1 # it fails on its own
[test_urllib2net.py]=1 # it fails on its own
[test_urllibnet.py]=1 # it fails on its own
[test_winreg.py]=1 # it fails on its own
[test_winsound.py]=1 # it fails on its own
[test_zlib.py]=1 # it fails on its own
[test_decimal.py]=1 #
[test_dis.py]=1 # We change line numbers - duh!
[test_generators.py]=1 # Investigate
[test_grammar.py]=1 # Too many stmts. Handle large stmts
[test_grp.py]=1 # Long test - might work Control flow?
[test_pep247.py]=1 # Long test - might work? Control flow?
[test_pwd.py]=1 # Long test - might work? Control flow?
[test_socketserver.py]=1 # -- test takes too long to run: 40 seconds
[test_threading.py]=1 # test takes too long to run: 11 seconds
[test_thread.py]=1 # test takes too long to run: 36 seconds
[test_trace.py]=1 # Long test - works
[test_zipfile64.py]=1 # Runs ok but takes 204 seconds
)
# About 243 files, 0 in 19 minutes

View File

@@ -1,4 +1,8 @@
SKIP_TESTS=( SKIP_TESTS=(
[test_platform.py]=1 # FIXME: Works on c90ff51
[test_pyclbr.py]=1 # FIXME: Works on c90ff51
[test_tempfile.py]=1 # FIXME: Works on c90ff51
[test_uu.py]=1 # FIXME: Works on c90ff51
[test_ftplib.py]=1 # FIXME: Works on c90ff51 [test_ftplib.py]=1 # FIXME: Works on c90ff51
[test___all__.py]=1 # it fails on its own [test___all__.py]=1 # it fails on its own
@@ -133,6 +137,8 @@ if (( batch )) ; then
SKIP_TESTS[test_distutils.py]=1 SKIP_TESTS[test_distutils.py]=1
SKIP_TESTS[test_exception_variations.py]=1 SKIP_TESTS[test_exception_variations.py]=1
SKIP_TESTS[test_poplib.py]=1 # May be a result of POWER installation
SKIP_TESTS[test_quopri.py]=1 SKIP_TESTS[test_quopri.py]=1
SKIP_TESTS[test_ioctl.py]=1 # it fails on its own SKIP_TESTS[test_ioctl.py]=1 # it fails on its own
SKIP_TESTS[test_tarfile.py]=1 # too long to run on POWER 15 secs SKIP_TESTS[test_tarfile.py]=1 # too long to run on POWER 15 secs

View File

@@ -1209,25 +1209,31 @@ class Python37Parser(Python37BaseParser):
elif opname == "BEFORE_ASYNC_WITH": elif opname == "BEFORE_ASYNC_WITH":
rules_str = """ rules_str = """
stmt ::= async_with_stmt stmt ::= async_with_stmt SETUP_ASYNC_WITH
async_with_pre ::= BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM SETUP_ASYNC_WITH
async_with_post ::= COME_FROM_ASYNC_WITH
WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
WITH_CLEANUP_FINISH END_FINALLY
stmt ::= async_with_as_stmt
async_with_as_stmt ::= expr async_with_as_stmt ::= expr
BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM async_with_pre
SETUP_ASYNC_WITH store store
suite_stmts_opt suite_stmts_opt
POP_BLOCK LOAD_CONST POP_BLOCK LOAD_CONST
COME_FROM_ASYNC_WITH async_with_post
WITH_CLEANUP_START
GET_AWAITABLE LOAD_CONST YIELD_FROM async_with_stmt ::= expr
WITH_CLEANUP_FINISH END_FINALLY async_with_pre
stmt ::= async_with_as_stmt POP_TOP
async_with_stmt ::= expr suite_stmts_opt
BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM POP_BLOCK LOAD_CONST
SETUP_ASYNC_WITH POP_TOP suite_stmts_opt async_with_post
POP_BLOCK LOAD_CONST async_with_stmt ::= expr
COME_FROM_ASYNC_WITH async_with_pre
WITH_CLEANUP_START POP_TOP
GET_AWAITABLE LOAD_CONST YIELD_FROM suite_stmts_opt
WITH_CLEANUP_FINISH END_FINALLY async_with_post
""" """
self.addRule(rules_str, nop_func) self.addRule(rules_str, nop_func)

View File

@@ -210,37 +210,57 @@ class Python37BaseParser(PythonParser):
if self.version < 3.8: if self.version < 3.8:
rules_str += """ rules_str += """
async_with_stmt ::= expr stmt ::= async_with_stmt SETUP_ASYNC_WITH
BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM async_with_stmt ::= expr
SETUP_ASYNC_WITH POP_TOP suite_stmts_opt async_with_pre
POP_BLOCK LOAD_CONST COME_FROM_ASYNC_WITH POP_TOP
WITH_CLEANUP_START suite_stmts_opt
GET_AWAITABLE LOAD_CONST YIELD_FROM POP_BLOCK LOAD_CONST
WITH_CLEANUP_FINISH END_FINALLY async_with_post
async_with_as_stmt ::= expr async_with_stmt ::= expr
BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM async_with_pre
SETUP_ASYNC_WITH store suite_stmts_opt POP_TOP
POP_BLOCK LOAD_CONST COME_FROM_ASYNC_WITH suite_stmts_opt
WITH_CLEANUP_START async_with_post
GET_AWAITABLE LOAD_CONST YIELD_FROM async_with_as_stmt ::= expr
WITH_CLEANUP_FINISH END_FINALLY async_with_pre
store
suite_stmts_opt
POP_BLOCK LOAD_CONST
async_with_post
""" """
else: else:
rules_str += """ rules_str += """
async_with_stmt ::= expr async_with_pre ::= BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM SETUP_ASYNC_WITH
BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM async_with_post ::= BEGIN_FINALLY COME_FROM_ASYNC_WITH
SETUP_ASYNC_WITH POP_TOP suite_stmts WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
POP_TOP POP_BLOCK BEGIN_FINALLY COME_FROM_ASYNC_WITH
WITH_CLEANUP_START
GET_AWAITABLE LOAD_CONST YIELD_FROM
WITH_CLEANUP_FINISH END_FINALLY WITH_CLEANUP_FINISH END_FINALLY
async_with_as_stmt ::= expr async_with_stmt ::= expr
BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM async_with_pre
SETUP_ASYNC_WITH store suite_stmts POP_TOP
POP_TOP POP_BLOCK BEGIN_FINALLY COME_FROM_ASYNC_WITH suite_stmts
WITH_CLEANUP_START POP_TOP POP_BLOCK
GET_AWAITABLE LOAD_CONST YIELD_FROM async_with_post
async_with_stmt ::= expr
async_with_pre
POP_TOP
suite_stmts
POP_BLOCK
BEGIN_FINALLY
WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
WITH_CLEANUP_FINISH POP_FINALLY LOAD_CONST RETURN_VALUE
COME_FROM_ASYNC_WITH
WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
WITH_CLEANUP_FINISH END_FINALLY WITH_CLEANUP_FINISH END_FINALLY
async_with_as_stmt ::= expr
async_with_pre
store suite_stmts
POP_TOP POP_BLOCK
async_with_post
async_with_as_stmt ::= expr
async_with_pre
store suite_stmts
POP_BLOCK async_with_post
""" """
self.addRule(rules_str, nop_func) self.addRule(rules_str, nop_func)

View File

@@ -61,12 +61,12 @@ def customize_for_version37(self, version):
(1, "expr"), (1, "expr"),
(16, "for_block"), (16, "for_block"),
), ),
"async_with_stmt": ("%|async with %c:\n%+%c%-", (0, "expr"), 7), "async_with_stmt": ("%|async with %c:\n%+%c%-", (0, "expr"), 3),
"async_with_as_stmt": ( "async_with_as_stmt": (
"%|async with %c as %c:\n%+%c%-", "%|async with %c as %c:\n%+%c%-",
(0, "expr"), (0, "expr"),
(6, "store"), (2, "store"),
7, 3,
), ),
"async_forelse_stmt": ( "async_forelse_stmt": (
"%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n", "%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n",