You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Merge branch 'master' into python-2.4
This commit is contained in:
BIN
test/bytecode_3.3/09_yield_from.pyc
Normal file
BIN
test/bytecode_3.3/09_yield_from.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
test/bytecode_3.4/09_yield_from.pyc
Normal file
BIN
test/bytecode_3.4/09_yield_from.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4_run/04_def_annotate.pyc
Normal file
BIN
test/bytecode_3.4_run/04_def_annotate.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -31,9 +31,22 @@ def test9(arg_1=55, *varargs: int, y=5, **kwargs):
|
||||
def test10(args_1, b: 'annotating b', c: int) -> float:
|
||||
return 5.4
|
||||
|
||||
class IOBase:
|
||||
def test11(*, name):
|
||||
return args, name
|
||||
|
||||
def test12(a, *args, name):
|
||||
return a, args
|
||||
pass
|
||||
|
||||
def test13(*args, name):
|
||||
return args, name
|
||||
|
||||
def test14(*args, name: int=1, qname):
|
||||
return args, name, qname
|
||||
|
||||
def test15(*args, name='S', fname, qname=4):
|
||||
return args, name, fname, qname
|
||||
|
||||
# Python 3.1 _pyio.py uses the -> "IOBase" annotation
|
||||
def o(f, mode = "r", buffering = None) -> "IOBase":
|
||||
return (f, mode, buffering)
|
||||
@@ -121,3 +134,8 @@ assert test6(2.3, 4, 5) == (2.3, 4, 5)
|
||||
|
||||
ann1(1, 'test', 5)
|
||||
ann2(1)
|
||||
|
||||
### FIXME: fill in...
|
||||
|
||||
assert test12(1, 2, 3, name='hi') == (1, (2, 3)), "a, *args, name"
|
||||
assert test13(1, 2, 3, name='hi') == ((1, 2, 3), 'hi'), "*args, name"
|
||||
|
@@ -11,6 +11,9 @@
|
||||
def _walk_dir(dir, dfile, ddir=None):
|
||||
yield from _walk_dir(dir, ddir=dfile)
|
||||
|
||||
def ybug(g):
|
||||
yield from g
|
||||
|
||||
# From 3.5.1 _wakrefset.py
|
||||
#
|
||||
# 3.5:
|
||||
|
@@ -175,6 +175,7 @@ class Python26Parser(Python2Parser):
|
||||
iflaststmt ::= testexpr_then c_stmts_opt JUMP_ABSOLUTE come_froms POP_TOP
|
||||
iflaststmt ::= testexpr c_stmts_opt JUMP_ABSOLUTE come_froms POP_TOP
|
||||
|
||||
# "if"/"else" statement that ends in a RETURN
|
||||
ifelsestmtr ::= testexpr_then return_if_stmts returns
|
||||
|
||||
testexpr_then ::= testtrue_then
|
||||
|
@@ -180,6 +180,8 @@ class Python27Parser(Python2Parser):
|
||||
ifelsestmtc ::= testexpr c_stmts_opt JUMP_ABSOLUTE else_suitec
|
||||
ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel
|
||||
ifelsestmtl ::= testexpr c_stmts_opt CONTINUE else_suitel
|
||||
|
||||
# "if"/"else" statement that ends in a RETURN
|
||||
ifelsestmtr ::= testexpr return_if_stmts COME_FROM returns
|
||||
|
||||
# Common with 2.6
|
||||
|
@@ -177,6 +177,7 @@ class Python3Parser(PythonParser):
|
||||
ifelsestmtc ::= testexpr c_stmts_opt JUMP_ABSOLUTE else_suitec
|
||||
ifelsestmtc ::= testexpr c_stmts_opt jump_absolute_else else_suitec
|
||||
|
||||
# "if"/"else" statement that ends in a RETURN
|
||||
ifelsestmtr ::= testexpr return_if_stmts returns
|
||||
|
||||
ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel
|
||||
|
@@ -350,11 +350,17 @@ TABLE_DIRECT = {
|
||||
'testtrue': ( 'not %p',
|
||||
(0, PRECEDENCE['unary_not']) ),
|
||||
|
||||
# Generally the args here are 0: (some sort of) "testexpr",
|
||||
# 1: (some sort of) "cstmts_opt",
|
||||
# 2 or 3: "else_suite"
|
||||
# But unfortunately there are irregularities, For example, 2.6- uses "testexpr_then"
|
||||
# and sometimes "cstmts" instead of "cstmts_opt" happens.
|
||||
# Down the line we might isolate these into version-specific rules.
|
||||
'ifelsestmt': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 3 ),
|
||||
'ifelsestmtc': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 3 ),
|
||||
'ifelsestmtl': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 3 ),
|
||||
'ifelsestmtr': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 2 ),
|
||||
'ifelsestmtr2': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-\n\n', 0, 1, 3 ), # has COME_FROM
|
||||
'ifelsestmtr2': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-\n\n', 0, 1, 3 ), # has COME_FROM in position 2
|
||||
|
||||
|
||||
# "elif" forms are not generated by the parser but are created through tree
|
||||
@@ -364,7 +370,7 @@ TABLE_DIRECT = {
|
||||
'elifstmt': ( '%|elif %c:\n%+%c%-', 0, 1 ),
|
||||
'elifelsestmt': ( '%|elif %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 3 ),
|
||||
'elifelsestmtr': ( '%|elif %c:\n%+%c%-%|else:\n%+%c%-\n\n', 0, 1, 2 ),
|
||||
'elifelsestmtr2': ( '%|elif %c:\n%+%c%-%|else:\n%+%c%-\n\n', 0, 1, 3 ), # has COME_FROM
|
||||
'elifelsestmtr2': ( '%|elif %c:\n%+%c%-%|else:\n%+%c%-\n\n', 0, 1, 3 ), # has COME_FROM in position 2
|
||||
|
||||
'whileTruestmt': ( '%|while True:\n%+%c%-\n\n', 1 ),
|
||||
'whilestmt': ( '%|while %c:\n%+%c%-\n\n', 1, 2 ),
|
||||
|
@@ -193,12 +193,12 @@ def customize_for_version3(self, version):
|
||||
def n_yield_from(node):
|
||||
self.write('yield from')
|
||||
self.write(' ')
|
||||
if 3.3 <= self.version <= 3.4:
|
||||
if 3.3 == self.version:
|
||||
self.preorder(node[0][0][0][0])
|
||||
elif self.version >= 3.5:
|
||||
elif self.version >= 3.4:
|
||||
self.preorder(node[0])
|
||||
else:
|
||||
assert False, "dunno about this python version"
|
||||
assert False, "Don't know how this Python handles 'yield from'."
|
||||
self.prune() # stop recursing
|
||||
self.n_yield_from = n_yield_from
|
||||
|
||||
|
@@ -142,8 +142,6 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
||||
i = len(paramnames) - len(defparams)
|
||||
suffix = ''
|
||||
|
||||
no_paramnames = len(paramnames[:i]) == 0
|
||||
|
||||
for param in paramnames[:i]:
|
||||
self.write(suffix, param)
|
||||
suffix = ', '
|
||||
@@ -164,7 +162,6 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
||||
suffix = ''
|
||||
for n in node:
|
||||
if n == 'pos_arg':
|
||||
no_paramnames = False
|
||||
self.write(suffix)
|
||||
param = paramnames[i]
|
||||
self.write(param)
|
||||
@@ -198,19 +195,16 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
||||
# self.println(indent, '#flags:\t', int(code.co_flags))
|
||||
ends_in_comma = False
|
||||
if kwonlyargcount > 0:
|
||||
if no_paramnames:
|
||||
if not code_has_star_arg(code):
|
||||
if argc > 0:
|
||||
self.write(", *, ")
|
||||
else:
|
||||
self.write("*, ")
|
||||
pass
|
||||
if not code_has_star_arg(code):
|
||||
if argc > 0:
|
||||
self.write(", *, ")
|
||||
else:
|
||||
self.write(", ")
|
||||
self.write("*, ")
|
||||
pass
|
||||
ends_in_comma = True
|
||||
else:
|
||||
if argc > 0:
|
||||
self.write(', ')
|
||||
self.write(", ")
|
||||
ends_in_comma = True
|
||||
|
||||
kw_args = [None] * kwonlyargcount
|
||||
@@ -230,8 +224,8 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
||||
pass
|
||||
|
||||
# handling other args
|
||||
ann_other_kw = [c == None for c in kw_args]
|
||||
for i, flag in enumerate(ann_other_kw):
|
||||
other_kw = [c == None for c in kw_args]
|
||||
for i, flag in enumerate(other_kw):
|
||||
if flag:
|
||||
n = kwargs[i]
|
||||
if n in annotate_dict:
|
||||
@@ -239,7 +233,8 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
||||
else:
|
||||
kw_args[i] = "%s" % n
|
||||
|
||||
self.write(', '.join(kw_args), ', ')
|
||||
self.write(', '.join(kw_args))
|
||||
ends_in_comma = False
|
||||
|
||||
else:
|
||||
if argc == 0:
|
||||
@@ -705,7 +700,6 @@ def make_function3(self, node, is_lambda, nested=1, code_node=None):
|
||||
kw_pairs = 0
|
||||
|
||||
i = len(paramnames) - len(defparams)
|
||||
no_paramnames = len(paramnames[:i]) == 0
|
||||
|
||||
# build parameters
|
||||
params = []
|
||||
@@ -768,52 +762,34 @@ def make_function3(self, node, is_lambda, nested=1, code_node=None):
|
||||
# Unless careful, We might lose line breaks though.
|
||||
ends_in_comma = False
|
||||
if kwonlyargcount > 0:
|
||||
if no_paramnames:
|
||||
if not (4 & code.co_flags):
|
||||
if argc > 0:
|
||||
self.write(", *, ")
|
||||
else:
|
||||
self.write("*, ")
|
||||
pass
|
||||
if not (4 & code.co_flags):
|
||||
if argc > 0:
|
||||
self.write(", *, ")
|
||||
else:
|
||||
self.write(", ")
|
||||
ends_in_comma = True
|
||||
self.write("*, ")
|
||||
pass
|
||||
ends_in_comma = True
|
||||
else:
|
||||
if argc > 0:
|
||||
self.write(', ')
|
||||
self.write(", ")
|
||||
ends_in_comma = True
|
||||
|
||||
# FIXME: this is not correct for 3.5. or 3.6 (which works different)
|
||||
# and 3.7?
|
||||
if 3.0 <= self.version <= 3.2:
|
||||
kwargs = node[0]
|
||||
last = len(kwargs)-1
|
||||
i = 0
|
||||
for n in node[0]:
|
||||
if n == 'kwarg':
|
||||
self.write('%s=' % n[0].attr)
|
||||
self.preorder(n[1])
|
||||
if i < last:
|
||||
self.write(', ')
|
||||
ends_in_comma = True
|
||||
pass
|
||||
else:
|
||||
ends_in_comma = False
|
||||
pass
|
||||
i += 1
|
||||
pass
|
||||
pass
|
||||
elif self.version <= 3.5:
|
||||
# FIXME this is not qute right for 3.5
|
||||
for n in node:
|
||||
if n == 'pos_arg':
|
||||
continue
|
||||
elif self.version >= 3.4 and not (n.kind in ('kwargs', 'no_kwargs', 'kwarg')):
|
||||
continue
|
||||
else:
|
||||
self.preorder(n)
|
||||
ends_in_comma = False
|
||||
break
|
||||
if 3.0 <= self.version <= 3.5:
|
||||
kw_args = [None] * kwonlyargcount
|
||||
kw_nodes = node[0]
|
||||
if kw_nodes == "kwargs":
|
||||
for n in kw_nodes:
|
||||
name = eval(n[0].pattr)
|
||||
default = self.traverse(n[1], indent='')
|
||||
idx = kwargs.index(name)
|
||||
kw_args[idx] = "%s=%s" % (name, default)
|
||||
|
||||
other_kw = [c == None for c in kw_args]
|
||||
|
||||
for i, flag in enumerate(other_kw):
|
||||
if flag:
|
||||
kw_args[i] = "%s" % kwargs[i]
|
||||
self.write(', '.join(kw_args))
|
||||
elif self.version >= 3.6:
|
||||
# argc = node[-1].attr
|
||||
# co = node[-3].attr
|
||||
@@ -862,16 +838,16 @@ def make_function3(self, node, is_lambda, nested=1, code_node=None):
|
||||
pass
|
||||
|
||||
# handle others
|
||||
if ann_dict:
|
||||
ann_other_kw = [c == None for c in kw_args]
|
||||
other_kw = [c == None for c in kw_args]
|
||||
|
||||
for i, flag in enumerate(other_kw):
|
||||
if flag:
|
||||
n = kwargs[i]
|
||||
if ann_dict and n in annotate_dict:
|
||||
kw_args[i] = "%s: %s" %(n, annotate_dict[n])
|
||||
else:
|
||||
kw_args[i] = "%s" % n
|
||||
|
||||
for i, flag in enumerate(ann_other_kw):
|
||||
if flag:
|
||||
n = kwargs[i]
|
||||
if n in annotate_dict:
|
||||
kw_args[i] = "%s: %s" %(n, annotate_dict[n])
|
||||
else:
|
||||
kw_args[i] = "%s" % n
|
||||
self.write(', '.join(kw_args))
|
||||
ends_in_comma = False
|
||||
|
||||
|
@@ -671,6 +671,11 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
n = n[0][0]
|
||||
elif n[0].kind in ('lastc_stmt', 'lastl_stmt'):
|
||||
n = n[0]
|
||||
if n[0].kind in ('ifstmt', 'iflaststmt', 'ifelsestmtl'):
|
||||
# This seems needed for Python 2.5-2.7
|
||||
n = n[0]
|
||||
pass
|
||||
pass
|
||||
else:
|
||||
if not preprocess:
|
||||
self.default(node)
|
||||
|
Reference in New Issue
Block a user