Wraps all integers in a call to Integer()
| 714 | assert line_t == 1 |
| 715 | |
| 716 | class IntegerWrapper(ast.NodeTransformer): |
| 717 | """Wraps all integers in a call to Integer()""" |
| 718 | |
| 719 | # for Python 3.7 and earlier |
| 720 | |
| 721 | # for Python 3.7 and earlier |
| 722 | def visit_Num(self, node): |
| 723 | if isinstance(node.n, int): |
| 724 | return ast.Call(func=ast.Name(id='Integer', ctx=ast.Load()), |
| 725 | args=[node], keywords=[]) |
| 726 | return node |
| 727 | |
| 728 | # For Python 3.8+ |
| 729 | def visit_Constant(self, node): |
| 730 | if isinstance(node.value, int): |
| 731 | return self.visit_Num(node) |
| 732 | return node |
| 733 | |
| 734 | |
| 735 | class TestAstTransform2(unittest.TestCase): |