MCPcopy Index your code
hub / github.com/evalplus/evalplus / void_calls

Function void_calls

tools/collect_valid_solutions.py:57–82  ·  view source on GitHub ↗
(source, functors, skip_main_fn=True)

Source from the content-addressed store, hash-verified

55
56
57def void_calls(source, functors, skip_main_fn=True):
58 changed = False
59
60 class FunctorTransformer(ast.NodeTransformer):
61 def __init__(self, target_functors):
62 super().__init__()
63 self.target_functors = target_functors
64
65 # visit func def
66 def visit_FunctionDef(self, node: ast.FunctionDef):
67 if skip_main_fn and node.name == "main":
68 return node
69 # visit child nodes
70 return self.generic_visit(node)
71
72 def visit_Call(self, node):
73 if isinstance(node.func, ast.Name) and node.func.id in self.target_functors:
74 nonlocal changed
75 changed = True
76 return ast.Expr(value=ast.Constant(value=None))
77 return node
78
79 tree = ast.parse(source)
80 code = astor.to_source(FunctorTransformer(functors).visit(tree))
81 fmt_code = black.format_str(code, mode=black.FileMode())
82 return (fmt_code, changed)
83
84
85def has_print_in_non_main_functions(source) -> bool:

Callers 1

scriptFunction · 0.85

Calls 1

FunctorTransformerClass · 0.85

Tested by

no test coverage detected