Created
October 9, 2015 21:18
-
-
Save aron-bordin/f4f7dd90a1bfc7357a40 to your computer and use it in GitHub Desktop.
Testing Python ast to safe-import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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