You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Merge branch 'master' into python-2.4
This commit is contained in:
14
NEWS.md
14
NEWS.md
@@ -1,3 +1,17 @@
|
||||
3.6.5: 2020-4-1 April Fool
|
||||
==========================
|
||||
|
||||
Back port some of the changes in decompile3 here which mostly helps 3.7 and 3.8 decompilation, although this may also help 3.6ish versions too.
|
||||
|
||||
- Handle nested `async for in for...` and Better async comprehension detection via `xdis`. Still more work is needed.
|
||||
- include token number in listings when `-g` and there is a parser error
|
||||
- remove unneded `Makefile`s now that remake 4.3+1.5dbg is a thing that has `-c`
|
||||
- Bug in finding annotations in functions with docstrings
|
||||
- Fix bug found by 2.4 sre_parse.py testing
|
||||
- Fix `transform` module's `ifelseif` bugs
|
||||
- Fix bug in 3.0 name module detection
|
||||
- Fix docstring detection
|
||||
|
||||
3.6.4: 2020-2-9 Plateau
|
||||
=======================
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -50,7 +50,7 @@ for VERSION in $PYVERSIONS ; do
|
||||
LOGFILE=/tmp/${MAIN}-$VERSION-$$.log
|
||||
|
||||
case "$VERSION" in
|
||||
3.7.6 | 3.8.1 | 3.1.5 | 3.0.1 )
|
||||
3.7.7 | 3.8.2 | 3.1.5 | 3.0.1 )
|
||||
continue
|
||||
;;
|
||||
3.5.9 )
|
||||
|
@@ -66,6 +66,14 @@ def div(a: dict(type=float, help='the dividend'),
|
||||
"""Divide a by b"""
|
||||
return a / b
|
||||
|
||||
# From 3.7.6 functools.py
|
||||
# Bug is in picking up the annotation.
|
||||
def f(a:"This is a new annotation"):
|
||||
"""This is a test"""
|
||||
assert f.__annotations__['a'] == "This is a new annotation"
|
||||
|
||||
f(5)
|
||||
|
||||
class TestSignatureObject1():
|
||||
def test_signature_on_wkwonly(self):
|
||||
def test(*, a:float, b:str, c:str = 'test', **kwargs: int) -> int:
|
||||
|
@@ -6,3 +6,11 @@ def make_arange(n):
|
||||
|
||||
async def run(m):
|
||||
return [i async for i in m]
|
||||
|
||||
# From 3.7.6 test_coroutines.py
|
||||
async def run_list(pair, f):
|
||||
return [i for pair in p async for i in f]
|
||||
|
||||
# FIXME: add this. It works in decompyle3
|
||||
# async def run_gen():
|
||||
# return (i async for i in f if 0 < i < 4)
|
||||
|
@@ -17,9 +17,9 @@ def ybug(g):
|
||||
# From 3.5.1 _wakrefset.py
|
||||
#
|
||||
# 3.5:
|
||||
# withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
||||
# POP_BLOCK LOAD_CONST COME_FROM
|
||||
# WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
# with ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
||||
# POP_BLOCK LOAD_CONST COME_FROM
|
||||
# WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
|
||||
|
||||
def __iter__(self, IterationGuard):
|
||||
|
@@ -1,7 +0,0 @@
|
||||
# Whatever it is you want to do, it should be forwarded to the
|
||||
# to top-level irectories
|
||||
PHONY=check all
|
||||
all: check
|
||||
|
||||
%:
|
||||
$(MAKE) -C .. $@
|
@@ -28,9 +28,10 @@ from uncompyle6.show import maybe_show_asm
|
||||
|
||||
|
||||
class ParserError(Exception):
|
||||
def __init__(self, token, offset):
|
||||
def __init__(self, token, offset, debug):
|
||||
self.token = token
|
||||
self.offset = offset
|
||||
self.debug = debug
|
||||
|
||||
def __str__(self):
|
||||
return "Parse error at or near `%r' instruction at offset %s\n" % (
|
||||
@@ -203,10 +204,10 @@ class PythonParser(GenericASTBuilder):
|
||||
indent = " "
|
||||
else:
|
||||
indent = "-> "
|
||||
print "%s%s" % (indent, instructions[i])
|
||||
raise ParserError(err_token, err_token.offset)
|
||||
print("%s%s" % (indent, instructions[i]))
|
||||
raise ParserError(err_token, err_token.offset, self.debug["reduce"])
|
||||
else:
|
||||
raise ParserError(None, -1)
|
||||
raise ParserError(None, -1, self.debug["reduce"])
|
||||
|
||||
def get_pos_kw(self, token):
|
||||
"""Return then the number of positional parameters and
|
||||
@@ -349,7 +350,7 @@ class PythonParser(GenericASTBuilder):
|
||||
stmt ::= try_except
|
||||
stmt ::= tryelsestmt
|
||||
stmt ::= tryfinallystmt
|
||||
stmt ::= withstmt
|
||||
stmt ::= with
|
||||
stmt ::= withasstmt
|
||||
|
||||
stmt ::= del_stmt
|
||||
|
@@ -85,8 +85,8 @@ class Python24Parser(Python25Parser):
|
||||
with_cleanup ::= LOAD_FAST DELETE_FAST WITH_CLEANUP END_FINALLY
|
||||
with_cleanup ::= LOAD_NAME DELETE_NAME WITH_CLEANUP END_FINALLY
|
||||
withasstmt ::= expr setupwithas store suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM with_cleanup
|
||||
withstmt ::= expr setupwith SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM with_cleanup
|
||||
stmt ::= withstmt
|
||||
with ::= expr setupwith SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM with_cleanup
|
||||
stmt ::= with
|
||||
stmt ::= withasstmt
|
||||
""")
|
||||
super(Python24Parser, self).customize_grammar_rules(tokens, customize)
|
||||
|
@@ -30,7 +30,7 @@ class Python25Parser(Python26Parser):
|
||||
setup_finally
|
||||
# opcode SETUP_WITH
|
||||
setupwith ::= DUP_TOP LOAD_ATTR store LOAD_ATTR CALL_FUNCTION_0 POP_TOP
|
||||
withstmt ::= expr setupwith SETUP_FINALLY suite_stmts_opt
|
||||
with ::= expr setupwith SETUP_FINALLY suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM with_cleanup
|
||||
|
||||
# Semantic actions want store to be at index 2
|
||||
@@ -70,7 +70,7 @@ class Python25Parser(Python26Parser):
|
||||
ifelsestmt ::= testexpr c_stmts_opt jf_cf_pop else_suite come_froms
|
||||
|
||||
setupwith ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 POP_TOP
|
||||
withstmt ::= expr setupwith SETUP_FINALLY suite_stmts_opt
|
||||
with ::= expr setupwith SETUP_FINALLY suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
|
||||
withasstmt ::= expr setupwithas store suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
|
||||
|
@@ -119,8 +119,8 @@ class Python26Parser(Python2Parser):
|
||||
ifelsestmtc ::= testexpr c_stmts_opt ja_cf_pop else_suitec
|
||||
|
||||
# Semantic actions want suite_stmts_opt to be at index 3
|
||||
withstmt ::= expr setupwith SETUP_FINALLY suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
|
||||
with ::= expr setupwith SETUP_FINALLY suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
|
||||
|
||||
# Semantic actions want store to be at index 2
|
||||
withasstmt ::= expr setupwithas store suite_stmts_opt
|
||||
|
@@ -143,7 +143,7 @@ class Python27Parser(Python2Parser):
|
||||
|
||||
for_block ::= returns _come_froms
|
||||
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
||||
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||
WITH_CLEANUP END_FINALLY
|
||||
|
||||
|
@@ -269,9 +269,9 @@ class Python3Parser(PythonParser):
|
||||
jmp_abs ::= JUMP_ABSOLUTE
|
||||
jmp_abs ::= JUMP_BACK
|
||||
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||
WITH_CLEANUP END_FINALLY
|
||||
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||
WITH_CLEANUP END_FINALLY
|
||||
|
||||
withasstmt ::= expr SETUP_WITH store suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||
|
@@ -211,7 +211,7 @@ class Python30Parser(Python31Parser):
|
||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK JUMP_BACK COME_FROM_LOOP
|
||||
whilestmt ::= SETUP_LOOP testexpr returns POP_TOP POP_BLOCK COME_FROM_LOOP
|
||||
withasstmt ::= expr SETUP_WITH store suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM_WITH WITH_CLEANUP END_FINALLY
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM_WITH WITH_CLEANUP END_FINALLY
|
||||
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM_WITH WITH_CLEANUP END_FINALLY
|
||||
|
||||
# lc_body ::= LOAD_FAST expr LIST_APPEND
|
||||
# lc_body ::= LOAD_NAME expr LIST_APPEND
|
||||
|
@@ -14,7 +14,7 @@ class Python31Parser(Python32Parser):
|
||||
|
||||
setupwith ::= DUP_TOP LOAD_ATTR store LOAD_ATTR CALL_FUNCTION_0 POP_TOP
|
||||
setupwithas ::= DUP_TOP LOAD_ATTR store LOAD_ATTR CALL_FUNCTION_0 store
|
||||
withstmt ::= expr setupwith SETUP_FINALLY
|
||||
with ::= expr setupwith SETUP_FINALLY
|
||||
suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_FINALLY
|
||||
load del_stmt WITH_CLEANUP END_FINALLY
|
||||
|
@@ -49,7 +49,7 @@ class Python35Parser(Python34Parser):
|
||||
|
||||
# Python 3.5+ has WITH_CLEANUP_START/FINISH
|
||||
|
||||
withstmt ::= expr
|
||||
with ::= expr
|
||||
SETUP_WITH POP_TOP suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
@@ -137,7 +137,7 @@ class Python35Parser(Python34Parser):
|
||||
self.remove_rules("""
|
||||
yield_from ::= expr GET_ITER LOAD_CONST YIELD_FROM
|
||||
yield_from ::= expr expr YIELD_FROM
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
||||
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||
WITH_CLEANUP END_FINALLY
|
||||
withasstmt ::= expr SETUP_WITH store suite_stmts_opt
|
||||
@@ -208,10 +208,10 @@ class Python35Parser(Python34Parser):
|
||||
elif opname == 'SETUP_WITH':
|
||||
# Python 3.5+ has WITH_CLEANUP_START/FINISH
|
||||
rules_str = """
|
||||
withstmt ::= expr
|
||||
SETUP_WITH POP_TOP suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
with ::= expr
|
||||
SETUP_WITH POP_TOP suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
|
||||
withasstmt ::= expr
|
||||
SETUP_WITH store suite_stmts_opt
|
||||
|
@@ -306,7 +306,7 @@ class Python36Parser(Python35Parser):
|
||||
self.check_reduce['assign'] = 'token'
|
||||
elif opname == 'SETUP_WITH':
|
||||
rules_str = """
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt COME_FROM_WITH
|
||||
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
|
||||
# Removes POP_BLOCK LOAD_CONST from 3.6-
|
||||
@@ -315,13 +315,13 @@ class Python36Parser(Python35Parser):
|
||||
"""
|
||||
if self.version < 3.8:
|
||||
rules_str += """
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
|
||||
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
|
||||
LOAD_CONST
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
"""
|
||||
else:
|
||||
rules_str += """
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
|
||||
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
|
||||
BEGIN_FINALLY COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH
|
||||
END_FINALLY
|
||||
|
@@ -1270,7 +1270,7 @@ class Python37Parser(Python37BaseParser):
|
||||
self.addRule(rule, nop_func)
|
||||
elif opname == "SETUP_WITH":
|
||||
rules_str = """
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt COME_FROM_WITH
|
||||
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
|
||||
# Removes POP_BLOCK LOAD_CONST from 3.6-
|
||||
@@ -1279,13 +1279,13 @@ class Python37Parser(Python37BaseParser):
|
||||
"""
|
||||
if self.version < 3.8:
|
||||
rules_str += """
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
|
||||
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
|
||||
LOAD_CONST
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
"""
|
||||
else:
|
||||
rules_str += """
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
|
||||
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
|
||||
BEGIN_FINALLY COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH
|
||||
END_FINALLY
|
||||
|
@@ -210,41 +210,86 @@ class Python37BaseParser(PythonParser):
|
||||
|
||||
if self.version < 3.8:
|
||||
rules_str += """
|
||||
stmt ::= async_with_stmt SETUP_ASYNC_WITH
|
||||
async_with_stmt ::= expr
|
||||
stmt ::= async_with_stmt SETUP_ASYNC_WITH
|
||||
c_stmt ::= c_async_with_stmt SETUP_ASYNC_WITH
|
||||
async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST
|
||||
async_with_post
|
||||
c_async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
c_suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST
|
||||
async_with_post
|
||||
async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts_opt
|
||||
async_with_post
|
||||
c_async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
c_suite_stmts_opt
|
||||
async_with_post
|
||||
async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store
|
||||
suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST
|
||||
async_with_post
|
||||
c_async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts_opt
|
||||
store
|
||||
c_suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST
|
||||
async_with_post
|
||||
async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts_opt
|
||||
async_with_post
|
||||
async_with_as_stmt ::= expr
|
||||
async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store
|
||||
suite_stmts_opt
|
||||
async_with_post
|
||||
c_async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store
|
||||
suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST
|
||||
async_with_post
|
||||
"""
|
||||
else:
|
||||
rules_str += """
|
||||
async_with_pre ::= BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM SETUP_ASYNC_WITH
|
||||
async_with_post ::= BEGIN_FINALLY COME_FROM_ASYNC_WITH
|
||||
WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||
WITH_CLEANUP_FINISH END_FINALLY
|
||||
async_with_stmt ::= expr
|
||||
async_with_pre ::= BEFORE_ASYNC_WITH GET_AWAITABLE LOAD_CONST YIELD_FROM SETUP_ASYNC_WITH
|
||||
async_with_post ::= BEGIN_FINALLY COME_FROM_ASYNC_WITH
|
||||
WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||
WITH_CLEANUP_FINISH END_FINALLY
|
||||
async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts
|
||||
POP_TOP POP_BLOCK
|
||||
async_with_post
|
||||
c_async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
c_suite_stmts
|
||||
POP_TOP POP_BLOCK
|
||||
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
|
||||
c_async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts
|
||||
POP_TOP POP_BLOCK
|
||||
async_with_post
|
||||
async_with_stmt ::= expr
|
||||
async_with_pre
|
||||
POP_TOP
|
||||
suite_stmts
|
||||
c_suite_stmts
|
||||
POP_BLOCK
|
||||
BEGIN_FINALLY
|
||||
WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||
@@ -252,15 +297,24 @@ class Python37BaseParser(PythonParser):
|
||||
COME_FROM_ASYNC_WITH
|
||||
WITH_CLEANUP_START GET_AWAITABLE LOAD_CONST YIELD_FROM
|
||||
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
|
||||
async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store suite_stmts
|
||||
POP_TOP POP_BLOCK
|
||||
async_with_post
|
||||
c_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
|
||||
c_async_with_as_stmt ::= expr
|
||||
async_with_pre
|
||||
store suite_stmts
|
||||
POP_BLOCK async_with_post
|
||||
"""
|
||||
self.addRule(rules_str, nop_func)
|
||||
|
||||
@@ -539,7 +593,7 @@ class Python37BaseParser(PythonParser):
|
||||
|
||||
stmt ::= genexpr_func_async
|
||||
|
||||
func_async_prefix ::= SETUP_EXCEPT GET_ANEXT LOAD_CONST YIELD_FROM
|
||||
func_async_prefix ::= _come_froms SETUP_EXCEPT GET_ANEXT LOAD_CONST YIELD_FROM
|
||||
func_async_middle ::= POP_BLOCK JUMP_FORWARD COME_FROM_EXCEPT
|
||||
DUP_TOP LOAD_GLOBAL COMPARE_OP POP_JUMP_IF_TRUE
|
||||
END_FINALLY COME_FROM
|
||||
@@ -548,22 +602,24 @@ class Python37BaseParser(PythonParser):
|
||||
JUMP_BACK COME_FROM
|
||||
POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_TOP
|
||||
|
||||
expr ::= listcomp_async
|
||||
listcomp_async ::= LOAD_LISTCOMP LOAD_STR MAKE_FUNCTION_0
|
||||
expr ::= list_comp_async
|
||||
list_comp_async ::= LOAD_LISTCOMP LOAD_STR MAKE_FUNCTION_0
|
||||
expr GET_AITER CALL_FUNCTION_1
|
||||
GET_AWAITABLE LOAD_CONST
|
||||
YIELD_FROM
|
||||
|
||||
expr ::= listcomp_async
|
||||
listcomp_async ::= BUILD_LIST_0 LOAD_FAST func_async_prefix
|
||||
expr ::= list_comp_async
|
||||
list_afor2 ::= func_async_prefix
|
||||
store func_async_middle list_iter
|
||||
JUMP_BACK COME_FROM
|
||||
POP_TOP POP_TOP POP_TOP POP_EXCEPT POP_TOP
|
||||
|
||||
list_comp_async ::= BUILD_LIST_0 LOAD_FAST list_afor2
|
||||
get_aiter ::= LOAD_DEREF GET_AITER
|
||||
list_afor ::= get_aiter list_afor2
|
||||
list_iter ::= list_afor
|
||||
""",
|
||||
nop_func,
|
||||
)
|
||||
custom_ops_processed.add(opname)
|
||||
elif opname == "JUMP_IF_NOT_DEBUG":
|
||||
v = token.attr
|
||||
self.addRule(
|
||||
@@ -939,15 +995,15 @@ class Python37BaseParser(PythonParser):
|
||||
|
||||
elif opname == "SETUP_WITH":
|
||||
rules_str = """
|
||||
stmt ::= withstmt
|
||||
stmt ::= with
|
||||
stmt ::= withasstmt
|
||||
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt COME_FROM_WITH
|
||||
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
withasstmt ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
|
||||
withstmt ::= expr
|
||||
with ::= expr
|
||||
SETUP_WITH POP_TOP suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
@@ -956,7 +1012,7 @@ class Python37BaseParser(PythonParser):
|
||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
|
||||
withstmt ::= expr
|
||||
with ::= expr
|
||||
SETUP_WITH POP_TOP suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
@@ -967,13 +1023,13 @@ class Python37BaseParser(PythonParser):
|
||||
"""
|
||||
if self.version < 3.8:
|
||||
rules_str += """
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
|
||||
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
|
||||
LOAD_CONST
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
"""
|
||||
else:
|
||||
rules_str += """
|
||||
withstmt ::= expr
|
||||
with ::= expr
|
||||
SETUP_WITH POP_TOP suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
@@ -982,7 +1038,7 @@ class Python37BaseParser(PythonParser):
|
||||
SETUP_WITH store suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_WITH
|
||||
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
|
||||
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
|
||||
BEGIN_FINALLY COME_FROM_WITH
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH
|
||||
END_FINALLY
|
||||
@@ -1128,8 +1184,17 @@ class Python37BaseParser(PythonParser):
|
||||
n = len(tokens)
|
||||
last = min(last, n-1)
|
||||
fn = self.reduce_check_table.get(lhs, None)
|
||||
if fn:
|
||||
return fn(self, lhs, n, rule, ast, tokens, first, last)
|
||||
try:
|
||||
if fn:
|
||||
return fn(self, lhs, n, rule, ast, tokens, first, last)
|
||||
except:
|
||||
import sys, traceback
|
||||
print("Exception in %s %s\n" +
|
||||
"rule: %s\n" +
|
||||
"offsets %s .. %s",
|
||||
(fn.__name__, sys.exc_info()[1], rule2str(rule), tokens[first].offset, otokens[last].offset))
|
||||
print(traceback.print_tb(sys.exc_info()[2],-1))
|
||||
raise ParserError(tokens[last], tokens[last].off2int(), self.debug["rules"])
|
||||
|
||||
if lhs in ("aug_assign1", "aug_assign2") and ast[0][0] == "and":
|
||||
return True
|
||||
|
@@ -6,6 +6,7 @@ from spark_parser.ast import AST as spark_AST
|
||||
if PYTHON3:
|
||||
intern = sys.intern
|
||||
|
||||
|
||||
class SyntaxTree(spark_AST):
|
||||
def __init__(self, *args, **kwargs):
|
||||
spark_AST.__init__(self, *args, **kwargs)
|
||||
@@ -17,7 +18,7 @@ class SyntaxTree(spark_AST):
|
||||
return len(self.data) == 1 and NoneToken == self.data[0]
|
||||
|
||||
def __repr__(self):
|
||||
return self.__repr1__('', None)
|
||||
return self.__repr1__("", None)
|
||||
|
||||
def __repr1__(self, indent, sibNum=None):
|
||||
rv = str(self.kind)
|
||||
@@ -33,16 +34,16 @@ class SyntaxTree(spark_AST):
|
||||
else:
|
||||
rv += " (transformed by %s)" % self.transformed_by
|
||||
rv = indent + rv
|
||||
indent += ' '
|
||||
indent += " "
|
||||
i = 0
|
||||
for node in self:
|
||||
if hasattr(node, '__repr1__'):
|
||||
if hasattr(node, "__repr1__"):
|
||||
if enumerate_children:
|
||||
child = node.__repr1__(indent, i)
|
||||
child = node.__repr1__(indent, i)
|
||||
else:
|
||||
child = node.__repr1__(indent, None)
|
||||
else:
|
||||
inst = node.format(line_prefix='L.')
|
||||
inst = node.format(line_prefix="")
|
||||
if inst.startswith("\n"):
|
||||
# Nuke leading \n
|
||||
inst = inst[1:]
|
||||
|
@@ -31,7 +31,7 @@ def customize_for_version25(self, version):
|
||||
# With/as is allowed as "from future" thing in 2.5
|
||||
# Note: It is safe to put the variables after "as" in parenthesis,
|
||||
# and sometimes it is needed.
|
||||
'withstmt': ( '%|with %c:\n%+%c%-', 0, 3),
|
||||
'with': ( '%|with %c:\n%+%c%-', 0, 3),
|
||||
'withasstmt': ( '%|with %c as (%c):\n%+%c%-', 0, 2, 3),
|
||||
})
|
||||
|
||||
|
@@ -17,6 +17,7 @@
|
||||
"""
|
||||
|
||||
from uncompyle6.semantics.consts import TABLE_DIRECT
|
||||
from xdis.util import co_flags_is_async
|
||||
|
||||
from xdis.code import iscode
|
||||
from uncompyle6.scanner import Code
|
||||
@@ -53,7 +54,7 @@ def customize_for_version3(self, version):
|
||||
"raise_stmt2": ("%|raise %c from %c\n", 0, 1),
|
||||
"tf_tryelsestmtl3": ( '%c%-%c%|else:\n%+%c', 1, 3, 5 ),
|
||||
"store_locals": ("%|# inspect.currentframe().f_locals = __locals__\n",),
|
||||
"withstmt": ("%|with %c:\n%+%c%-", 0, 3),
|
||||
"with": ("%|with %c:\n%+%c%-", 0, 3),
|
||||
"withasstmt": ("%|with %c as (%c):\n%+%c%-", 0, 2, 3),
|
||||
}
|
||||
)
|
||||
@@ -87,7 +88,9 @@ def customize_for_version3(self, version):
|
||||
p = self.prec
|
||||
self.prec = 27
|
||||
|
||||
code = Code(node[1].attr, self.scanner, self.currentclass)
|
||||
code_obj = node[1].attr
|
||||
assert iscode(code_obj)
|
||||
code = Code(code_obj, self.scanner, self.currentclass)
|
||||
ast = self.build_ast(code._tokens, code._customize)
|
||||
self.customize(code._customize)
|
||||
|
||||
@@ -141,7 +144,10 @@ def customize_for_version3(self, version):
|
||||
# Find the list comprehension body. It is the inner-most
|
||||
# node that is not list_.. .
|
||||
while n == "list_iter":
|
||||
n = n[0] # recurse one step
|
||||
|
||||
# recurse one step
|
||||
n = n[0]
|
||||
|
||||
if n == "list_for":
|
||||
stores.append(n[2])
|
||||
n = n[3]
|
||||
@@ -168,6 +174,11 @@ def customize_for_version3(self, version):
|
||||
list_ifs.append(n)
|
||||
n = n[-1]
|
||||
pass
|
||||
elif n == "list_afor":
|
||||
collections.append(n[0][0])
|
||||
n = n[1]
|
||||
stores.append(n[1][0])
|
||||
n = n[3]
|
||||
pass
|
||||
|
||||
assert n == "lc_body", ast
|
||||
@@ -175,7 +186,13 @@ def customize_for_version3(self, version):
|
||||
self.preorder(n[0])
|
||||
|
||||
# FIXME: add indentation around "for"'s and "in"'s
|
||||
n_colls = len(collections)
|
||||
for i, store in enumerate(stores):
|
||||
if i >= n_colls:
|
||||
break
|
||||
if collections[i] == "LOAD_DEREF" and co_flags_is_async(code_obj.co_flags):
|
||||
self.write(" async")
|
||||
pass
|
||||
self.write(" for ")
|
||||
self.preorder(store)
|
||||
self.write(" in ")
|
||||
|
@@ -16,7 +16,7 @@
|
||||
"""
|
||||
|
||||
from xdis.code import iscode
|
||||
from xdis.util import COMPILER_FLAG_BIT
|
||||
from xdis.util import co_flags_is_async
|
||||
from uncompyle6.semantics.consts import (
|
||||
INDENT_PER_LEVEL,
|
||||
PRECEDENCE,
|
||||
@@ -207,14 +207,7 @@ def customize_for_version35(self, version):
|
||||
pass
|
||||
|
||||
is_code = hasattr(code_node, "attr") and iscode(code_node.attr)
|
||||
return is_code and (
|
||||
code_node.attr.co_flags
|
||||
& (
|
||||
COMPILER_FLAG_BIT["COROUTINE"]
|
||||
| COMPILER_FLAG_BIT["ITERABLE_COROUTINE"]
|
||||
| COMPILER_FLAG_BIT["ASYNC_GENERATOR"]
|
||||
)
|
||||
)
|
||||
return is_code and co_flags_is_async(code_node.attr.co_flags)
|
||||
|
||||
def n_function_def(node):
|
||||
if is_async_fn(node):
|
||||
|
@@ -295,3 +295,13 @@ def customize_for_version37(self, version):
|
||||
return
|
||||
|
||||
self.n_importlist37 = n_importlist37
|
||||
|
||||
def n_list_comp_async(node):
|
||||
self.write("[")
|
||||
if node[0].kind == "load_closure":
|
||||
self.listcomp_closure3(node)
|
||||
else:
|
||||
self.comprehension_walk_newer(node, iter_index=3, code_index=0)
|
||||
self.write("]")
|
||||
self.prune()
|
||||
self.n_list_comp_async = n_list_comp_async
|
||||
|
@@ -88,7 +88,11 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
||||
else:
|
||||
pos_args, kw_args, annotate_argc, closure = args_attr
|
||||
|
||||
i = -4
|
||||
if node[-2] != "docstring":
|
||||
i = -4
|
||||
else:
|
||||
i = -5
|
||||
|
||||
kw_pairs = 0
|
||||
if annotate_argc:
|
||||
# Turn into subroutine and DRY with other use
|
||||
|
@@ -1207,7 +1207,11 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
|
||||
is_30_dict_comp = False
|
||||
store = None
|
||||
n = ast[iter_index]
|
||||
if node == "list_comp_async":
|
||||
n = ast[2][1]
|
||||
else:
|
||||
n = ast[iter_index]
|
||||
|
||||
if ast in (
|
||||
"set_comp_func",
|
||||
"dict_comp_func",
|
||||
@@ -1237,8 +1241,8 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
n = k[0]
|
||||
pass
|
||||
pass
|
||||
elif ast == "listcomp_async":
|
||||
store = ast[3]
|
||||
elif ast == "list_comp_async":
|
||||
store = ast[2][1]
|
||||
else:
|
||||
assert n == "list_iter", n
|
||||
|
||||
@@ -1287,7 +1291,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
# Python 2.7+ starts including set_comp_body
|
||||
# Python 3.5+ starts including set_comp_func
|
||||
# Python 3.0 is yet another snowflake
|
||||
if self.version != 3.0:
|
||||
if self.version != 3.0 and self.version < 3.7:
|
||||
assert n.kind in (
|
||||
"lc_body",
|
||||
"list_if37",
|
||||
@@ -1313,7 +1317,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
else:
|
||||
self.preorder(n[0])
|
||||
|
||||
if node == "listcomp_async":
|
||||
if node == "list_comp_async":
|
||||
self.write(" async")
|
||||
in_node_index = 3
|
||||
else:
|
||||
@@ -1363,7 +1367,6 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.comprehension_walk_newer(node, list_iter_index, 0)
|
||||
self.write("]")
|
||||
self.prune()
|
||||
n_listcomp_async = n_listcomp
|
||||
|
||||
def setcomprehension_walk3(self, node, collection_index):
|
||||
"""Set comprehensions the way they are done in Python3.
|
||||
|
@@ -262,8 +262,11 @@ class TreeTransform(GenericASTTraversal, object):
|
||||
old_stmts = None
|
||||
else_suite_index = 1
|
||||
|
||||
if len(n) == 1 == len(n[0]) and n[0] == "stmt":
|
||||
len_n = len(n)
|
||||
if len_n == 1 == len(n[0]) and n[0] == "stmt":
|
||||
n = n[0][0]
|
||||
elif len_n == 0:
|
||||
return node
|
||||
elif n[0].kind in ("lastc_stmt", "lastl_stmt"):
|
||||
n = n[0]
|
||||
if n[0].kind in (
|
||||
@@ -282,14 +285,14 @@ class TreeTransform(GenericASTTraversal, object):
|
||||
pass
|
||||
else:
|
||||
if (
|
||||
len(n) > 1
|
||||
len_n > 1
|
||||
and isinstance(n[0], SyntaxTree)
|
||||
and 1 == len(n[0])
|
||||
and n[0] == "stmt"
|
||||
and n[1].kind == "stmt"
|
||||
):
|
||||
else_suite_stmts = n[0]
|
||||
elif len(n) == 1:
|
||||
elif len_n == 1:
|
||||
else_suite_stmts = n
|
||||
else:
|
||||
return node
|
||||
|
@@ -12,4 +12,4 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# This file is suitable for sourcing inside bash as
|
||||
# well as importing into Python
|
||||
VERSION="3.6.4" # noqa
|
||||
VERSION="3.6.5" # noqa
|
||||
|
Reference in New Issue
Block a user