def rewriter(rewrite): def visit(self, t): return ast.copy_location(rewrite(self, self.generic_visit(t)), t) return visit