Skip to content

Instantly share code, notes, and snippets.

@aron-bordin
Created October 9, 2015 21:18
Show Gist options
  • Save aron-bordin/f4f7dd90a1bfc7357a40 to your computer and use it in GitHub Desktop.
Save aron-bordin/f4f7dd90a1bfc7357a40 to your computer and use it in GitHub Desktop.
Testing Python ast to safe-import
import ast
import codegen
class CallWrapper(ast.NodeTransformer):
def visit_Call(self, node):
if node.col_offset == 0:
return None
return node
src = open('test1.py').read()
p = ast.parse(src)
CallWrapper().visit(p)
ast.fix_missing_locations(p)
print(codegen.to_source(p))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment