def n_mkfunc(self, node): """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. """ code = find_code_node(node, -3).attr mkfunc_pattr = node[-1].pattr if isinstance(mkfunc_pattr, tuple): assert isinstance(mkfunc_pattr, tuple) assert len(mkfunc_pattr, 4) and isinstance(mkfunc_pattr, int) is_closure = node[-1].pattr[3] != 0 else: # FIXME: This is what we had before. It is hoaky and probably wrong. is_closure = mkfunc_pattr == "closure" if ((not is_closure) and len(code.co_consts) > 0 and isinstance(code.co_consts[0], str)): docstring_node = SyntaxTree( "docstring", [Token("LOAD_STR", has_arg=True, pattr=code.co_consts[0])], transformed_by="n_mkfunc", ) node = SyntaxTree( "mkfunc", node[:-1] + [docstring_node, node[-1]], transformed_by="n_mkfunc", ) return node
def n_mkfunc(self, node): """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. """ code = find_code_node(node, -3).attr if ( node[-1].pattr != "closure" and len(code.co_consts) > 0 and code.co_consts[0] is not None ): docstring_node = SyntaxTree( "docstring", [Token("LOAD_STR", has_arg=True, pattr=code.co_consts[0])], transformed_by="n_mkfunc", ) node = SyntaxTree( "mkfunc", node[:-1] + [docstring_node, node[-1]], transformed_by="n_mkfunc", ) return node