You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
More annotation processing in to make_function
Move return-value annotation determination from n_mkfunc_annotate to make_function_annotate which is where other kinds of annotation handling will also need to be done.
This commit is contained in:
@@ -47,7 +47,7 @@ def find_none(node):
|
|||||||
# FIXME: DRY the below code...
|
# FIXME: DRY the below code...
|
||||||
|
|
||||||
def make_function3_annotate(self, node, isLambda, nested=1,
|
def make_function3_annotate(self, node, isLambda, nested=1,
|
||||||
codeNode=None, annotate=None):
|
codeNode=None, annotate_last=-1):
|
||||||
"""
|
"""
|
||||||
Dump function defintion, doc string, and function
|
Dump function defintion, doc string, and function
|
||||||
body. This code is specialized for Python 3"""
|
body. This code is specialized for Python 3"""
|
||||||
@@ -70,6 +70,17 @@ def make_function3_annotate(self, node, isLambda, nested=1,
|
|||||||
# MAKE_FUNCTION_... or MAKE_CLOSURE_...
|
# MAKE_FUNCTION_... or MAKE_CLOSURE_...
|
||||||
assert node[-1].type.startswith('MAKE_')
|
assert node[-1].type.startswith('MAKE_')
|
||||||
|
|
||||||
|
annotate_return = None
|
||||||
|
annotate_arg = node[annotate_last]
|
||||||
|
|
||||||
|
if (annotate_arg == 'annotate_arg'
|
||||||
|
and annotate_arg[0] == 'LOAD_CONST'
|
||||||
|
and isinstance(annotate_arg[0].attr, tuple)):
|
||||||
|
annotate_tup = annotate_arg[0].attr
|
||||||
|
if annotate_tup[-1] == 'return':
|
||||||
|
annotate_return = node[annotate_last-1][0].attr
|
||||||
|
pass
|
||||||
|
|
||||||
args_node = node[-1]
|
args_node = node[-1]
|
||||||
if isinstance(args_node.attr, tuple):
|
if isinstance(args_node.attr, tuple):
|
||||||
# positional args are before kwargs
|
# positional args are before kwargs
|
||||||
@@ -177,8 +188,8 @@ def make_function3_annotate(self, node, isLambda, nested=1,
|
|||||||
self.write(": ")
|
self.write(": ")
|
||||||
else:
|
else:
|
||||||
self.write(')')
|
self.write(')')
|
||||||
if annotate:
|
if annotate_return:
|
||||||
self.write(' -> "%s"' % annotate)
|
self.write(' -> "%s"' % annotate_return)
|
||||||
self.println(":")
|
self.println(":")
|
||||||
|
|
||||||
if (len(code.co_consts) > 0 and
|
if (len(code.co_consts) > 0 and
|
||||||
|
@@ -597,20 +597,11 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
code = node[-3]
|
code = node[-3]
|
||||||
|
|
||||||
self.indentMore()
|
self.indentMore()
|
||||||
annotate_return = None
|
|
||||||
annotate_last = -4 if self.version == 3.1 else -5
|
annotate_last = -4 if self.version == 3.1 else -5
|
||||||
annotate_arg = node[annotate_last]
|
|
||||||
|
|
||||||
if (annotate_arg == 'annotate_arg'
|
|
||||||
and annotate_arg[0] == 'LOAD_CONST'
|
|
||||||
and isinstance(annotate_arg[0].attr, tuple)):
|
|
||||||
annotate_tup = annotate_arg[0].attr
|
|
||||||
if annotate_tup[-1] == 'return':
|
|
||||||
annotate_return = node[annotate_last-1][0].attr
|
|
||||||
pass
|
|
||||||
# FIXME: handle and pass full annotate args
|
# FIXME: handle and pass full annotate args
|
||||||
make_function3_annotate(self, node, isLambda=False,
|
make_function3_annotate(self, node, isLambda=False,
|
||||||
codeNode=code, annotate=annotate_return)
|
codeNode=code, annotate_last=annotate_last)
|
||||||
|
|
||||||
if len(self.param_stack) > 1:
|
if len(self.param_stack) > 1:
|
||||||
self.write('\n\n')
|
self.write('\n\n')
|
||||||
|
Reference in New Issue
Block a user