Dump function definition, doc string, and function body in Python version 3.6 and above.
(self, node, is_lambda, nested=1, code_node=None)
| 35 | |
| 36 | |
| 37 | def make_function36(self, node, is_lambda, nested=1, code_node=None): |
| 38 | """Dump function definition, doc string, and function body in |
| 39 | Python version 3.6 and above. |
| 40 | """ |
| 41 | |
| 42 | # MAKE_CLOSURE adds a closure slot |
| 43 | |
| 44 | # In Python 3.6 and above stack change again. I understand |
| 45 | # 3.7 changes some of those changes, although I don't |
| 46 | # see it in this code yet. Yes, it is hard to follow, |
| 47 | # and I am sure I haven't been able to keep up. |
| 48 | |
| 49 | # Thank you, Python. |
| 50 | |
| 51 | def build_param(ast, name, default, annotation=None): |
| 52 | """build parameters: |
| 53 | - handle defaults |
| 54 | - handle format tuple parameters |
| 55 | """ |
| 56 | value = default |
| 57 | if annotation: |
| 58 | result = "%s: %s=%s" % (name, annotation, value) |
| 59 | else: |
| 60 | result = "%s=%s" % (name, value) |
| 61 | |
| 62 | # The below can probably be removed. This is probably |
| 63 | # a holdover from days when LOAD_CONST erroneously |
| 64 | # didn't handle LOAD_CONST None properly |
| 65 | if result[-2:] == "= ": # default was 'LOAD_CONST None' |
| 66 | result += "None" |
| 67 | |
| 68 | return result |
| 69 | |
| 70 | # MAKE_FUNCTION_... or MAKE_CLOSURE_... |
| 71 | assert node[-1].kind.startswith("MAKE_") |
| 72 | |
| 73 | # Python 3.3+ adds a qualified name at TOS (-1) |
| 74 | # moving down the LOAD_LAMBDA instruction |
| 75 | lambda_index = -3 |
| 76 | |
| 77 | args_node = node[-1] |
| 78 | |
| 79 | annotate_dict = {} |
| 80 | |
| 81 | # Get a list of tree nodes that constitute the values for the "default |
| 82 | # parameters"; these are default values that appear before any *, and are |
| 83 | # not to be confused with keyword parameters which may appear after *. |
| 84 | args_attr = args_node.attr |
| 85 | |
| 86 | if len(args_attr) == 3: |
| 87 | _, kw_args, annotate_argc = args_attr |
| 88 | else: |
| 89 | _, kw_args, annotate_argc, closure = args_attr |
| 90 | |
| 91 | if node[-2] != "docstring": |
| 92 | i = -4 |
| 93 | else: |
| 94 | i = -5 |
no test coverage detected