Wraps all integers in a call to Integer()
| 853 | |
| 854 | |
| 855 | class IntegerWrapper(ast.NodeTransformer): |
| 856 | """Wraps all integers in a call to Integer()""" |
| 857 | |
| 858 | # for Python 3.7 and earlier |
| 859 | def visit_Num(self, node): |
| 860 | if isinstance(node.value, int): |
| 861 | return ast.Call( |
| 862 | func=ast.Name(id="Integer", ctx=ast.Load()), args=[node], keywords=[] |
| 863 | ) |
| 864 | return node |
| 865 | |
| 866 | # For Python 3.8+ |
| 867 | def visit_Constant(self, node): |
| 868 | if isinstance(node.value, int): |
| 869 | return self.visit_Num(node) |
| 870 | return node |
| 871 | |
| 872 | |
| 873 | class TestAstTransform2(unittest.TestCase): |