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:
|
def test10(args_1, b: 'annotating b', c: int) -> float:
|
||||||
return 5.4
|
return 5.4
|
||||||
|
|
||||||
class IOBase:
|
def test11(*, name):
|
||||||
|
return args, name
|
||||||
|
|
||||||
|
def test12(a, *args, name):
|
||||||
|
return a, args
|
||||||
pass
|
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
|
# Python 3.1 _pyio.py uses the -> "IOBase" annotation
|
||||||
def o(f, mode = "r", buffering = None) -> "IOBase":
|
def o(f, mode = "r", buffering = None) -> "IOBase":
|
||||||
return (f, mode, buffering)
|
return (f, mode, buffering)
|
||||||
@@ -121,3 +134,8 @@ assert test6(2.3, 4, 5) == (2.3, 4, 5)
|
|||||||
|
|
||||||
ann1(1, 'test', 5)
|
ann1(1, 'test', 5)
|
||||||
ann2(1)
|
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):
|
def _walk_dir(dir, dfile, ddir=None):
|
||||||
yield from _walk_dir(dir, ddir=dfile)
|
yield from _walk_dir(dir, ddir=dfile)
|
||||||
|
|
||||||
|
def ybug(g):
|
||||||
|
yield from g
|
||||||
|
|
||||||
# From 3.5.1 _wakrefset.py
|
# From 3.5.1 _wakrefset.py
|
||||||
#
|
#
|
||||||
# 3.5:
|
# 3.5:
|
||||||
|
@@ -175,6 +175,7 @@ class Python26Parser(Python2Parser):
|
|||||||
iflaststmt ::= testexpr_then c_stmts_opt JUMP_ABSOLUTE come_froms POP_TOP
|
iflaststmt ::= testexpr_then c_stmts_opt JUMP_ABSOLUTE come_froms POP_TOP
|
||||||
iflaststmt ::= testexpr 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
|
ifelsestmtr ::= testexpr_then return_if_stmts returns
|
||||||
|
|
||||||
testexpr_then ::= testtrue_then
|
testexpr_then ::= testtrue_then
|
||||||
|
@@ -180,6 +180,8 @@ class Python27Parser(Python2Parser):
|
|||||||
ifelsestmtc ::= testexpr c_stmts_opt JUMP_ABSOLUTE else_suitec
|
ifelsestmtc ::= testexpr c_stmts_opt JUMP_ABSOLUTE else_suitec
|
||||||
ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel
|
ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel
|
||||||
ifelsestmtl ::= testexpr c_stmts_opt CONTINUE 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
|
ifelsestmtr ::= testexpr return_if_stmts COME_FROM returns
|
||||||
|
|
||||||
# Common with 2.6
|
# 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_suitec
|
||||||
ifelsestmtc ::= testexpr c_stmts_opt jump_absolute_else 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
|
ifelsestmtr ::= testexpr return_if_stmts returns
|
||||||
|
|
||||||
ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel
|
ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel
|
||||||
|
@@ -350,11 +350,17 @@ TABLE_DIRECT = {
|
|||||||
'testtrue': ( 'not %p',
|
'testtrue': ( 'not %p',
|
||||||
(0, PRECEDENCE['unary_not']) ),
|
(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 ),
|
'ifelsestmt': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 3 ),
|
||||||
'ifelsestmtc': ( '%|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 ),
|
'ifelsestmtl': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 3 ),
|
||||||
'ifelsestmtr': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 2 ),
|
'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
|
# "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 ),
|
'elifstmt': ( '%|elif %c:\n%+%c%-', 0, 1 ),
|
||||||
'elifelsestmt': ( '%|elif %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 3 ),
|
'elifelsestmt': ( '%|elif %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 3 ),
|
||||||
'elifelsestmtr': ( '%|elif %c:\n%+%c%-%|else:\n%+%c%-\n\n', 0, 1, 2 ),
|
'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 ),
|
'whileTruestmt': ( '%|while True:\n%+%c%-\n\n', 1 ),
|
||||||
'whilestmt': ( '%|while %c:\n%+%c%-\n\n', 1, 2 ),
|
'whilestmt': ( '%|while %c:\n%+%c%-\n\n', 1, 2 ),
|
||||||
|
@@ -193,12 +193,12 @@ def customize_for_version3(self, version):
|
|||||||
def n_yield_from(node):
|
def n_yield_from(node):
|
||||||
self.write('yield from')
|
self.write('yield from')
|
||||||
self.write(' ')
|
self.write(' ')
|
||||||
if 3.3 <= self.version <= 3.4:
|
if 3.3 == self.version:
|
||||||
self.preorder(node[0][0][0][0])
|
self.preorder(node[0][0][0][0])
|
||||||
elif self.version >= 3.5:
|
elif self.version >= 3.4:
|
||||||
self.preorder(node[0])
|
self.preorder(node[0])
|
||||||
else:
|
else:
|
||||||
assert False, "dunno about this python version"
|
assert False, "Don't know how this Python handles 'yield from'."
|
||||||
self.prune() # stop recursing
|
self.prune() # stop recursing
|
||||||
self.n_yield_from = n_yield_from
|
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)
|
i = len(paramnames) - len(defparams)
|
||||||
suffix = ''
|
suffix = ''
|
||||||
|
|
||||||
no_paramnames = len(paramnames[:i]) == 0
|
|
||||||
|
|
||||||
for param in paramnames[:i]:
|
for param in paramnames[:i]:
|
||||||
self.write(suffix, param)
|
self.write(suffix, param)
|
||||||
suffix = ', '
|
suffix = ', '
|
||||||
@@ -164,7 +162,6 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
|||||||
suffix = ''
|
suffix = ''
|
||||||
for n in node:
|
for n in node:
|
||||||
if n == 'pos_arg':
|
if n == 'pos_arg':
|
||||||
no_paramnames = False
|
|
||||||
self.write(suffix)
|
self.write(suffix)
|
||||||
param = paramnames[i]
|
param = paramnames[i]
|
||||||
self.write(param)
|
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))
|
# self.println(indent, '#flags:\t', int(code.co_flags))
|
||||||
ends_in_comma = False
|
ends_in_comma = False
|
||||||
if kwonlyargcount > 0:
|
if kwonlyargcount > 0:
|
||||||
if no_paramnames:
|
if not code_has_star_arg(code):
|
||||||
if not code_has_star_arg(code):
|
if argc > 0:
|
||||||
if argc > 0:
|
self.write(", *, ")
|
||||||
self.write(", *, ")
|
|
||||||
else:
|
|
||||||
self.write("*, ")
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
self.write(", ")
|
self.write("*, ")
|
||||||
|
pass
|
||||||
ends_in_comma = True
|
ends_in_comma = True
|
||||||
else:
|
else:
|
||||||
if argc > 0:
|
if argc > 0:
|
||||||
self.write(', ')
|
self.write(", ")
|
||||||
ends_in_comma = True
|
ends_in_comma = True
|
||||||
|
|
||||||
kw_args = [None] * kwonlyargcount
|
kw_args = [None] * kwonlyargcount
|
||||||
@@ -230,8 +224,8 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# handling other args
|
# handling other args
|
||||||
ann_other_kw = [c == None for c in kw_args]
|
other_kw = [c == None for c in kw_args]
|
||||||
for i, flag in enumerate(ann_other_kw):
|
for i, flag in enumerate(other_kw):
|
||||||
if flag:
|
if flag:
|
||||||
n = kwargs[i]
|
n = kwargs[i]
|
||||||
if n in annotate_dict:
|
if n in annotate_dict:
|
||||||
@@ -239,7 +233,8 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
|||||||
else:
|
else:
|
||||||
kw_args[i] = "%s" % n
|
kw_args[i] = "%s" % n
|
||||||
|
|
||||||
self.write(', '.join(kw_args), ', ')
|
self.write(', '.join(kw_args))
|
||||||
|
ends_in_comma = False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if argc == 0:
|
if argc == 0:
|
||||||
@@ -705,7 +700,6 @@ def make_function3(self, node, is_lambda, nested=1, code_node=None):
|
|||||||
kw_pairs = 0
|
kw_pairs = 0
|
||||||
|
|
||||||
i = len(paramnames) - len(defparams)
|
i = len(paramnames) - len(defparams)
|
||||||
no_paramnames = len(paramnames[:i]) == 0
|
|
||||||
|
|
||||||
# build parameters
|
# build parameters
|
||||||
params = []
|
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.
|
# Unless careful, We might lose line breaks though.
|
||||||
ends_in_comma = False
|
ends_in_comma = False
|
||||||
if kwonlyargcount > 0:
|
if kwonlyargcount > 0:
|
||||||
if no_paramnames:
|
if not (4 & code.co_flags):
|
||||||
if not (4 & code.co_flags):
|
if argc > 0:
|
||||||
if argc > 0:
|
self.write(", *, ")
|
||||||
self.write(", *, ")
|
|
||||||
else:
|
|
||||||
self.write("*, ")
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
self.write(", ")
|
self.write("*, ")
|
||||||
ends_in_comma = True
|
pass
|
||||||
|
ends_in_comma = True
|
||||||
else:
|
else:
|
||||||
if argc > 0:
|
if argc > 0:
|
||||||
self.write(', ')
|
self.write(", ")
|
||||||
ends_in_comma = True
|
ends_in_comma = True
|
||||||
|
|
||||||
# FIXME: this is not correct for 3.5. or 3.6 (which works different)
|
if 3.0 <= self.version <= 3.5:
|
||||||
# and 3.7?
|
kw_args = [None] * kwonlyargcount
|
||||||
if 3.0 <= self.version <= 3.2:
|
kw_nodes = node[0]
|
||||||
kwargs = node[0]
|
if kw_nodes == "kwargs":
|
||||||
last = len(kwargs)-1
|
for n in kw_nodes:
|
||||||
i = 0
|
name = eval(n[0].pattr)
|
||||||
for n in node[0]:
|
default = self.traverse(n[1], indent='')
|
||||||
if n == 'kwarg':
|
idx = kwargs.index(name)
|
||||||
self.write('%s=' % n[0].attr)
|
kw_args[idx] = "%s=%s" % (name, default)
|
||||||
self.preorder(n[1])
|
|
||||||
if i < last:
|
other_kw = [c == None for c in kw_args]
|
||||||
self.write(', ')
|
|
||||||
ends_in_comma = True
|
for i, flag in enumerate(other_kw):
|
||||||
pass
|
if flag:
|
||||||
else:
|
kw_args[i] = "%s" % kwargs[i]
|
||||||
ends_in_comma = False
|
self.write(', '.join(kw_args))
|
||||||
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
|
|
||||||
elif self.version >= 3.6:
|
elif self.version >= 3.6:
|
||||||
# argc = node[-1].attr
|
# argc = node[-1].attr
|
||||||
# co = node[-3].attr
|
# co = node[-3].attr
|
||||||
@@ -862,16 +838,16 @@ def make_function3(self, node, is_lambda, nested=1, code_node=None):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# handle others
|
# handle others
|
||||||
if ann_dict:
|
other_kw = [c == None for c in kw_args]
|
||||||
ann_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))
|
self.write(', '.join(kw_args))
|
||||||
ends_in_comma = False
|
ends_in_comma = False
|
||||||
|
|
||||||
|
@@ -671,6 +671,11 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
n = n[0][0]
|
n = n[0][0]
|
||||||
elif n[0].kind in ('lastc_stmt', 'lastl_stmt'):
|
elif n[0].kind in ('lastc_stmt', 'lastl_stmt'):
|
||||||
n = n[0]
|
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:
|
else:
|
||||||
if not preprocess:
|
if not preprocess:
|
||||||
self.default(node)
|
self.default(node)
|
||||||
|
Reference in New Issue
Block a user