You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Revise annotation type implementation for < 3.6
This commit is contained in:
@@ -135,10 +135,6 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
|||||||
indent = ' ' * l
|
indent = ' ' * l
|
||||||
line_number = self.line_number
|
line_number = self.line_number
|
||||||
|
|
||||||
if code_has_star_arg(code):
|
|
||||||
self.write('*%s' % code.co_varnames[argc + kw_pairs])
|
|
||||||
argc += 1
|
|
||||||
|
|
||||||
i = len(paramnames) - len(defparams)
|
i = len(paramnames) - len(defparams)
|
||||||
suffix = ''
|
suffix = ''
|
||||||
|
|
||||||
@@ -148,7 +144,7 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
|||||||
self.write(suffix, param)
|
self.write(suffix, param)
|
||||||
suffix = ', '
|
suffix = ', '
|
||||||
if param in annotate_tuple[0].attr:
|
if param in annotate_tuple[0].attr:
|
||||||
p = annotate_tuple[0].attr.index(param)
|
p = annotate_tuple[0].attr.index(param) + pos_args
|
||||||
self.write(': ')
|
self.write(': ')
|
||||||
self.preorder(node[p])
|
self.preorder(node[p])
|
||||||
if (line_number != self.line_number):
|
if (line_number != self.line_number):
|
||||||
@@ -187,7 +183,17 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
|||||||
suffix = ', '
|
suffix = ', '
|
||||||
|
|
||||||
|
|
||||||
|
if code_has_star_arg(code):
|
||||||
|
star_arg = code.co_varnames[argc + kw_pairs]
|
||||||
|
self.write(suffix, '*%s' % star_arg)
|
||||||
|
if star_arg in annotate_tuple[0].attr:
|
||||||
|
p = annotate_tuple[0].attr.index(star_arg) + pos_args
|
||||||
|
self.write(': ')
|
||||||
|
self.preorder(node[p])
|
||||||
|
argc += 1
|
||||||
|
|
||||||
# self.println(indent, '#flags:\t', int(code.co_flags))
|
# self.println(indent, '#flags:\t', int(code.co_flags))
|
||||||
|
ends_in_comma = False
|
||||||
if kw_args + annotate_argc > 0:
|
if kw_args + annotate_argc > 0:
|
||||||
if no_paramnames:
|
if no_paramnames:
|
||||||
if not code_has_star_arg(code):
|
if not code_has_star_arg(code):
|
||||||
@@ -198,6 +204,7 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.write(", ")
|
self.write(", ")
|
||||||
|
ends_in_comma = True
|
||||||
|
|
||||||
kwargs = node[0]
|
kwargs = node[0]
|
||||||
last = len(kwargs)-1
|
last = len(kwargs)-1
|
||||||
@@ -211,36 +218,24 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
|||||||
self.preorder(n[1])
|
self.preorder(n[1])
|
||||||
if i < last:
|
if i < last:
|
||||||
self.write(', ')
|
self.write(', ')
|
||||||
|
ends_in_comma = True
|
||||||
|
else:
|
||||||
|
ends_in_comma = False
|
||||||
i += 1
|
i += 1
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
annotate_args = []
|
|
||||||
for n in node:
|
|
||||||
if n == 'annotate_arg':
|
|
||||||
annotate_args.append(n[0])
|
|
||||||
elif n == 'annotate_tuple':
|
|
||||||
t = n[0].attr
|
|
||||||
if t[-1] == 'return':
|
|
||||||
t = t[0:-1]
|
|
||||||
annotate_args = annotate_args[:-1]
|
|
||||||
pass
|
|
||||||
last = len(annotate_args) - 1
|
|
||||||
for i in range(len(annotate_args)):
|
|
||||||
self.write("%s: " % (t[i]))
|
|
||||||
self.preorder(annotate_args[i])
|
|
||||||
if i < last:
|
|
||||||
self.write(', ')
|
|
||||||
pass
|
|
||||||
pass
|
|
||||||
break
|
|
||||||
pass
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if code_has_star_star_arg(code):
|
if code_has_star_star_arg(code):
|
||||||
if argc > 0:
|
if argc > 0 and not ends_in_comma:
|
||||||
self.write(', ')
|
self.write(', ')
|
||||||
self.write('**%s' % code.co_varnames[argc + kw_pairs])
|
star_star_arg = code.co_varnames[argc + kw_pairs]
|
||||||
|
self.write('**%s' % star_star_arg)
|
||||||
|
if star_star_arg in annotate_tuple[0].attr:
|
||||||
|
p = annotate_tuple[0].attr.index(star_star_arg) + pos_args
|
||||||
|
self.write(': ')
|
||||||
|
self.preorder(node[p])
|
||||||
|
|
||||||
if is_lambda:
|
if is_lambda:
|
||||||
self.write(": ")
|
self.write(": ")
|
||||||
|
Reference in New Issue
Block a user