MCPcopy
hub / github.com/rocky/python-uncompyle6 / make_function3_annotate

Function make_function3_annotate

uncompyle6/semantics/make_function3.py:36–298  ·  view source on GitHub ↗

Dump function definition, doc string, and function body. This code is specialized for Python 3

(
    self, node, is_lambda, nested=1, code_node=None, annotate_last=-1
)

Source from the content-addressed store, hash-verified

34
35
36def make_function3_annotate(
37 self, node, is_lambda, nested=1, code_node=None, annotate_last=-1
38):
39 """
40 Dump function definition, doc string, and function
41 body. This code is specialized for Python 3"""
42
43 def build_param(ast, name, default):
44 """build parameters:
45 - handle defaults
46 - handle format tuple parameters
47 """
48 if default:
49 value = self.traverse(default, indent="")
50 maybe_show_tree_param_default(self, name, value)
51 result = "%s=%s" % (name, value)
52 if result[-2:] == "= ": # default was 'LOAD_CONST None'
53 result += "None"
54 return result
55 else:
56 return name
57
58 # MAKE_FUNCTION_... or MAKE_CLOSURE_...
59 assert node[-1].kind.startswith("MAKE_")
60
61 annotate_tuple = None
62 for annotate_last in range(len(node) - 1, -1, -1):
63 if node[annotate_last] == "annotate_tuple":
64 annotate_tuple = node[annotate_last]
65 break
66 annotate_args = {}
67
68 if (
69 annotate_tuple == "annotate_tuple"
70 and annotate_tuple[0] in ("LOAD_CONST", "LOAD_NAME")
71 and isinstance(annotate_tuple[0].attr, tuple)
72 ):
73 annotate_tup = annotate_tuple[0].attr
74 i = -1
75 j = annotate_last - 1
76 l = -len(node)
77 while j >= l and node[j].kind in ("annotate_arg", "annotate_tuple"):
78 annotate_args[annotate_tup[i]] = node[j][0]
79 i -= 1
80 j -= 1
81
82 args_node = node[-1]
83 if isinstance(args_node.attr, tuple):
84 # positional args are before kwargs
85 defparams = node[: args_node.attr[0]]
86 pos_args, kw_args, annotate_argc = args_node.attr
87 else:
88 defparams = node[: args_node.attr]
89 kw_args = 0
90 pass
91
92 annotate_dict = {}
93

Callers 1

n_mkfunc_annotateFunction · 0.90

Calls 13

CodeClass · 0.90
print_docstringFunction · 0.90
find_all_globalsFunction · 0.90
find_noneFunction · 0.90
keysMethod · 0.45
traverseMethod · 0.45
build_astMethod · 0.45
writeMethod · 0.45
preorderMethod · 0.45
joinMethod · 0.45
printlnMethod · 0.45

Tested by

no test coverage detected