If the function has a docstring (this is found in the code constants), pull that out and make it part of the syntax tree. When generating the source string that AST node rather than the code field is seen and used.
(self, node)
| 113 | return node |
| 114 | |
| 115 | def n_mkfunc(self, node): |
| 116 | """If the function has a docstring (this is found in the code |
| 117 | constants), pull that out and make it part of the syntax |
| 118 | tree. When generating the source string that AST node rather |
| 119 | than the code field is seen and used. |
| 120 | """ |
| 121 | |
| 122 | if self.version >= (3, 7): |
| 123 | code_index = -3 |
| 124 | else: |
| 125 | code_index = -2 |
| 126 | |
| 127 | code = find_code_node(node, code_index).attr |
| 128 | |
| 129 | mkfunc_pattr = node[-1].pattr |
| 130 | if isinstance(mkfunc_pattr, tuple): |
| 131 | assert isinstance(mkfunc_pattr, tuple) |
| 132 | assert len(mkfunc_pattr) == 4 and isinstance(mkfunc_pattr, int) |
| 133 | |
| 134 | if len(code.co_consts) > 0 and isinstance(code.co_consts[0], str): |
| 135 | docstring_node = SyntaxTree( |
| 136 | "docstring", [Token("LOAD_STR", has_arg=True, pattr=code.co_consts[0])] |
| 137 | ) |
| 138 | docstring_node.transformed_by = "n_mkfunc" |
| 139 | node = SyntaxTree("mkfunc", node[:-1] + [docstring_node, node[-1]]) |
| 140 | node.transformed_by = "n_mkfunc" |
| 141 | |
| 142 | return node |
| 143 | |
| 144 | def n_ifstmt(self, node): |
| 145 | """Here we check if we can turn an `ifstmt` or 'iflaststmtl` into |
nothing calls this directly
no test coverage detected