def visit_Num(self, node):
"""
WARNING: you cannot directly write constants in list. It will throw obscure
error like "TypeError: required field "lineno" missing from expr"
You MUST wrap all constants in ast_demo types, like ast_demo.Num(n=42) instead of raw 42
"""
n = node.n
if isinstance(n, int):
new_node = ast.Call(func=ast.Name(id='Fraction', ctx=ast.Load()),
args=[node, ast.Num(n=1)], keywords=[])
ast.copy_location(new_node, node)
# ast_demo.fix_missing_locations(new_node)
return new_node
return node
评论列表
文章目录