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
)
| 34 | |
| 35 | |
| 36 | def 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 |
no test coverage detected