You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Fix 3.6 async parsing
This commit is contained in:
@@ -12,7 +12,6 @@ SKIP_TESTS=(
|
||||
[test_aifc.py]=1 #
|
||||
[test_argparse.py]=1 # it fails on its own
|
||||
[test_asdl_parser.py]=1 # it fails on its own
|
||||
[test_asyncgen.py]=1 # parse error
|
||||
[test_atexit.py]=1 # The atexit test looks for specific comments in error lines
|
||||
|
||||
[test_baseexception.py]=1 # test assert error
|
||||
@@ -39,9 +38,9 @@ SKIP_TESTS=(
|
||||
[test_collections.py]= # it fails on its own
|
||||
[test_compile.py]=1 # Code introspects on co_consts in a non-decompilable way
|
||||
[test_concurrent_futures.py]=1 # Takes long
|
||||
[test_contextlib.py]=1 # test assertion failure
|
||||
[test_contextlib_async.py]=1 # Investigate
|
||||
[test_coroutines.py]=1 # parse error
|
||||
|
||||
[test_coroutines.py]=1 # FIXME: async parse error
|
||||
|
||||
[test_curses.py]=1 # Parse error
|
||||
[test_ctypes.py]=1 # it fails on its own
|
||||
|
||||
|
@@ -29,7 +29,13 @@ class Python36Parser(Python35Parser):
|
||||
self.customized = {}
|
||||
|
||||
|
||||
def p_36misc(self, args):
|
||||
def p_jump_36(self, args):
|
||||
"""
|
||||
# Zero or one COME_FROM
|
||||
# And/or expressions have this
|
||||
come_from_opt ::= COME_FROM?
|
||||
"""
|
||||
def p_misc_36(self, args):
|
||||
"""sstmt ::= sstmt RETURN_LAST
|
||||
|
||||
# long except clauses in a loop can sometimes cause a JUMP_BACK to turn into a
|
||||
@@ -67,6 +73,33 @@ class Python36Parser(Python35Parser):
|
||||
|
||||
if_exp ::= expr jmp_false expr jf_cf expr COME_FROM
|
||||
|
||||
async_for_stmt36 ::= SETUP_LOOP expr
|
||||
GET_AITER
|
||||
LOAD_CONST YIELD_FROM
|
||||
SETUP_EXCEPT GET_ANEXT LOAD_CONST
|
||||
YIELD_FROM
|
||||
store
|
||||
POP_BLOCK JUMP_BACK COME_FROM_EXCEPT DUP_TOP
|
||||
LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_TRUE
|
||||
END_FINALLY for_block
|
||||
COME_FROM
|
||||
POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_TOP POP_BLOCK
|
||||
COME_FROM_LOOP
|
||||
|
||||
async_for_stmt36 ::= SETUP_LOOP expr
|
||||
GET_AITER
|
||||
LOAD_CONST YIELD_FROM SETUP_EXCEPT GET_ANEXT LOAD_CONST
|
||||
YIELD_FROM
|
||||
store
|
||||
POP_BLOCK JUMP_FORWARD COME_FROM_EXCEPT DUP_TOP
|
||||
LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_TRUE
|
||||
END_FINALLY
|
||||
COME_FROM
|
||||
for_block
|
||||
COME_FROM
|
||||
POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_TOP POP_BLOCK
|
||||
COME_FROM_LOOP
|
||||
|
||||
async_for_stmt ::= SETUP_LOOP expr
|
||||
GET_AITER
|
||||
LOAD_CONST YIELD_FROM SETUP_EXCEPT GET_ANEXT LOAD_CONST
|
||||
@@ -81,20 +114,6 @@ class Python36Parser(Python35Parser):
|
||||
|
||||
stmt ::= async_for_stmt36
|
||||
|
||||
async_for_stmt36 ::= SETUP_LOOP expr
|
||||
GET_AITER
|
||||
LOAD_CONST YIELD_FROM
|
||||
SETUP_EXCEPT GET_ANEXT LOAD_CONST
|
||||
YIELD_FROM
|
||||
store
|
||||
POP_BLOCK JUMP_BACK COME_FROM_EXCEPT DUP_TOP
|
||||
LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_TRUE
|
||||
END_FINALLY for_block
|
||||
COME_FROM
|
||||
POP_TOP POP_TOP POP_TOP POP_EXCEPT
|
||||
POP_TOP POP_BLOCK
|
||||
COME_FROM_LOOP
|
||||
|
||||
async_forelse_stmt ::= SETUP_LOOP expr
|
||||
GET_AITER
|
||||
LOAD_CONST YIELD_FROM SETUP_EXCEPT GET_ANEXT LOAD_CONST
|
||||
|
@@ -28,6 +28,7 @@ from uncompyle6.semantics.helper import flatten_list, gen_function_parens_adjust
|
||||
# Python 3.5+ Changes #
|
||||
#######################
|
||||
def customize_for_version35(self, version):
|
||||
# fmt: off
|
||||
TABLE_DIRECT.update(
|
||||
{
|
||||
# nested await expressions like:
|
||||
@@ -36,15 +37,24 @@ def customize_for_version35(self, version):
|
||||
"await_expr": ("await %p", (0, PRECEDENCE["await_expr"]-1)),
|
||||
|
||||
"await_stmt": ("%|%c\n", 0),
|
||||
"async_for_stmt": ("%|async for %c in %c:\n%+%|%c%-\n\n", 9, 1, 25),
|
||||
"async_for_stmt": (
|
||||
"%|async for %c in %c:\n%+%|%c%-\n\n",
|
||||
(9, "store"),
|
||||
(1, "expr"),
|
||||
(25, "for_block"),
|
||||
),
|
||||
"async_forelse_stmt": (
|
||||
"%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n",
|
||||
9,
|
||||
1,
|
||||
25,
|
||||
(9, "store"),
|
||||
(1, "expr"),
|
||||
(25, "for_block"),
|
||||
(27, "else_suite"),
|
||||
),
|
||||
"async_with_stmt": ("%|async with %c:\n%+%c%-", (0, "expr"), 3),
|
||||
"async_with_stmt": (
|
||||
"%|async with %c:\n%+%c%-",
|
||||
(0, "expr"),
|
||||
3
|
||||
),
|
||||
"async_with_as_stmt": (
|
||||
"%|async with %c as %c:\n%+%c%-",
|
||||
(0, "expr"),
|
||||
@@ -55,6 +65,7 @@ def customize_for_version35(self, version):
|
||||
# "unmapexpr": ( "{**%c}", 0), # done by n_unmapexpr
|
||||
}
|
||||
)
|
||||
# fmt: on
|
||||
|
||||
def async_call(node):
|
||||
self.f.write("async ")
|
||||
|
@@ -61,7 +61,7 @@ def customize_for_version36(self, version):
|
||||
"%|async for %c in %c:\n%+%c%-\n\n",
|
||||
(9, "store"),
|
||||
(1, "expr"),
|
||||
(18, "for_block"),
|
||||
(-9, "for_block"), # Count from end, since COME_FROM shifts things in the forward direction
|
||||
),
|
||||
"call_ex": ("%c(%p)", (0, "expr"), (1, 100)),
|
||||
"except_return": ("%|except:\n%+%c%-", 3),
|
||||
|
Reference in New Issue
Block a user