You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Merge branch 'python-3.3-to-3.5' into python-3.0-to-3.2
This commit is contained in:
@@ -16,7 +16,7 @@ class Python32Parser(Python3Parser):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def p_gen_comp(self, args):
|
def p_gen_comp32(self, args):
|
||||||
"""
|
"""
|
||||||
genexpr_func ::= LOAD_ARG FOR_ITER store comp_iter JUMP_BACK
|
genexpr_func ::= LOAD_ARG FOR_ITER store comp_iter JUMP_BACK
|
||||||
"""
|
"""
|
||||||
|
@@ -19,8 +19,9 @@ class Python33Parser(Python32Parser):
|
|||||||
def customize_grammar_rules(self, tokens, customize):
|
def customize_grammar_rules(self, tokens, customize):
|
||||||
self.remove_rules("""
|
self.remove_rules("""
|
||||||
# 3.3+ adds POP_BLOCKS
|
# 3.3+ adds POP_BLOCKS
|
||||||
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP COME_FROM_LOOP
|
genexpr_func ::= LOAD_ARG FOR_ITER store comp_iter JUMP_BACK
|
||||||
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK NOP COME_FROM_LOOP
|
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK NOP COME_FROM_LOOP
|
||||||
|
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP COME_FROM_LOOP
|
||||||
""")
|
""")
|
||||||
super(Python33Parser, self).customize_grammar_rules(tokens, customize)
|
super(Python33Parser, self).customize_grammar_rules(tokens, customize)
|
||||||
return
|
return
|
||||||
|
@@ -403,7 +403,7 @@ class Python37Parser(Python37BaseParser):
|
|||||||
list_if_not ::= expr jmp_true list_iter
|
list_if_not ::= expr jmp_true list_iter
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def p_gen_comp(self, args):
|
def p_gen_comp37(self, args):
|
||||||
"""
|
"""
|
||||||
comp_iter ::= comp_for
|
comp_iter ::= comp_for
|
||||||
comp_body ::= gen_comp_body
|
comp_body ::= gen_comp_body
|
||||||
|
@@ -25,6 +25,7 @@ from xdis import (
|
|||||||
)
|
)
|
||||||
from uncompyle6.scanner import Code
|
from uncompyle6.scanner import Code
|
||||||
from uncompyle6.semantics.parser_error import ParserError
|
from uncompyle6.semantics.parser_error import ParserError
|
||||||
|
from uncompyle6.parser import ParserError as ParserError2
|
||||||
from uncompyle6.semantics.helper import (
|
from uncompyle6.semantics.helper import (
|
||||||
find_all_globals,
|
find_all_globals,
|
||||||
find_globals_and_nonlocals,
|
find_globals_and_nonlocals,
|
||||||
@@ -38,11 +39,12 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
|||||||
"""Dump function definition, doc string, and function body in
|
"""Dump function definition, doc string, and function body in
|
||||||
Python version 3.6 and above.
|
Python version 3.6 and above.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# MAKE_CLOSURE adds an additional closure slot
|
# MAKE_CLOSURE adds an additional closure slot
|
||||||
|
|
||||||
# In Python 3.6 and above stack change again. I understand
|
# In Python 3.6 and above stack change again. I understand
|
||||||
# 3.7 changes some of those changes, although I don't
|
# 3.7 changes some of those changes, although I don't
|
||||||
# see it in this code yet. Yes, it is hard to follow
|
# see it in this code yet. Yes, it is hard to follow,
|
||||||
# and I am sure I haven't been able to keep up.
|
# and I am sure I haven't been able to keep up.
|
||||||
|
|
||||||
# Thank you, Python.
|
# Thank you, Python.
|
||||||
@@ -84,16 +86,15 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
|||||||
args_attr = args_node.attr
|
args_attr = args_node.attr
|
||||||
|
|
||||||
if len(args_attr) == 3:
|
if len(args_attr) == 3:
|
||||||
pos_args, kw_args, annotate_argc = args_attr
|
_, kw_args, annotate_argc = args_attr
|
||||||
else:
|
else:
|
||||||
pos_args, kw_args, annotate_argc, closure = args_attr
|
_, kw_args, annotate_argc, closure = args_attr
|
||||||
|
|
||||||
if node[-2] != "docstring":
|
if node[-2] != "docstring":
|
||||||
i = -4
|
i = -4
|
||||||
else:
|
else:
|
||||||
i = -5
|
i = -5
|
||||||
|
|
||||||
kw_pairs = 0
|
|
||||||
if annotate_argc:
|
if annotate_argc:
|
||||||
# Turn into subroutine and DRY with other use
|
# Turn into subroutine and DRY with other use
|
||||||
annotate_node = node[i]
|
annotate_node = node[i]
|
||||||
@@ -105,9 +106,9 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
|||||||
):
|
):
|
||||||
types = [self.traverse(n, indent="") for n in annotate_node[:-2]]
|
types = [self.traverse(n, indent="") for n in annotate_node[:-2]]
|
||||||
names = annotate_node[-2].attr
|
names = annotate_node[-2].attr
|
||||||
l = len(types)
|
length = len(types)
|
||||||
assert l == len(names)
|
assert length == len(names)
|
||||||
for i in range(l):
|
for i in range(length):
|
||||||
annotate_dict[names[i]] = types[i]
|
annotate_dict[names[i]] = types[i]
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
@@ -118,11 +119,6 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
|||||||
# annotate = node[i]
|
# annotate = node[i]
|
||||||
i -= 1
|
i -= 1
|
||||||
|
|
||||||
if kw_args:
|
|
||||||
kw_node = node[pos_args]
|
|
||||||
if kw_node == "expr":
|
|
||||||
kw_node = kw_node[0]
|
|
||||||
|
|
||||||
defparams = []
|
defparams = []
|
||||||
# FIXME: DRY with code below
|
# FIXME: DRY with code below
|
||||||
default, kw_args, annotate_argc = args_node.attr[0:3]
|
default, kw_args, annotate_argc = args_node.attr[0:3]
|
||||||
@@ -180,9 +176,7 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
|||||||
if defparams:
|
if defparams:
|
||||||
for i, defparam in enumerate(defparams):
|
for i, defparam in enumerate(defparams):
|
||||||
params.append(
|
params.append(
|
||||||
build_param(
|
build_param(paramnames[i], defparam, annotate_dict.get(paramnames[i]))
|
||||||
ast, paramnames[i], defparam, annotate_dict.get(paramnames[i])
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for param in paramnames[i + 1 :]:
|
for param in paramnames[i + 1 :]:
|
||||||
@@ -235,7 +229,7 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
|||||||
|
|
||||||
ends_in_comma = False
|
ends_in_comma = False
|
||||||
if kwonlyargcount > 0:
|
if kwonlyargcount > 0:
|
||||||
if not (4 & code.co_flags):
|
if not 4 & code.co_flags:
|
||||||
if argc > 0:
|
if argc > 0:
|
||||||
self.write(", *, ")
|
self.write(", *, ")
|
||||||
else:
|
else:
|
||||||
@@ -299,7 +293,7 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
|||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
# handle others
|
# handle others
|
||||||
other_kw = [c == None for c in kw_args]
|
other_kw = [c is None for c in kw_args]
|
||||||
|
|
||||||
for i, flag in enumerate(other_kw):
|
for i, flag in enumerate(other_kw):
|
||||||
if flag:
|
if flag:
|
||||||
|
Reference in New Issue
Block a user