Show More
@@ -610,15 +610,16 b' class TestModules(tt.TempFileMixin, unittest.TestCase):' | |||
|
610 | 610 | class Negator(ast.NodeTransformer): |
|
611 | 611 | """Negates all number literals in an AST.""" |
|
612 | 612 | |
|
613 | # for python 3.7 and earlier | |
|
613 | 614 | def visit_Num(self, node): |
|
614 | 615 | node.n = -node.n |
|
615 | 616 | return node |
|
616 | 617 | |
|
617 | if sys.version_info > (3,8): | |
|
618 |
|
|
|
619 |
|
|
|
620 |
|
|
|
621 |
|
|
|
618 | # for python 3.8+ | |
|
619 | def visit_Constant(self, node): | |
|
620 | if isinstance(node.value, int): | |
|
621 | return self.visit_Num(node) | |
|
622 | return node | |
|
622 | 623 | |
|
623 | 624 | class TestAstTransform(unittest.TestCase): |
|
624 | 625 | def setUp(self): |
@@ -681,17 +682,21 b' class TestAstTransform(unittest.TestCase):' | |||
|
681 | 682 | |
|
682 | 683 | class IntegerWrapper(ast.NodeTransformer): |
|
683 | 684 | """Wraps all integers in a call to Integer()""" |
|
685 | ||
|
686 | # for Python 3.7 and earlier | |
|
687 | ||
|
688 | # for Python 3.7 and earlier | |
|
684 | 689 | def visit_Num(self, node): |
|
685 | 690 | if isinstance(node.n, int): |
|
686 | 691 | return ast.Call(func=ast.Name(id='Integer', ctx=ast.Load()), |
|
687 | 692 | args=[node], keywords=[]) |
|
688 | 693 | return node |
|
689 | 694 | |
|
690 | if sys.version_info > (3,8): | |
|
691 |
|
|
|
692 |
|
|
|
693 |
|
|
|
694 |
|
|
|
695 | # For Python 3.8+ | |
|
696 | def visit_Constant(self, node): | |
|
697 | if isinstance(node.value, int): | |
|
698 | return self.visit_Num(node) | |
|
699 | return node | |
|
695 | 700 | |
|
696 | 701 | |
|
697 | 702 | class TestAstTransform2(unittest.TestCase): |
@@ -734,14 +739,16 b' class TestAstTransform2(unittest.TestCase):' | |||
|
734 | 739 | |
|
735 | 740 | class ErrorTransformer(ast.NodeTransformer): |
|
736 | 741 | """Throws an error when it sees a number.""" |
|
742 | ||
|
743 | # for Python 3.7 and earlier | |
|
737 | 744 | def visit_Num(self, node): |
|
738 | 745 | raise ValueError("test") |
|
739 | 746 | |
|
740 | if sys.version_info > (3,8): | |
|
741 |
|
|
|
742 |
|
|
|
743 |
|
|
|
744 |
|
|
|
747 | # for Python 3.8+ | |
|
748 | def visit_Constant(self, node): | |
|
749 | if isinstance(node.value, int): | |
|
750 | return self.visit_Num(node) | |
|
751 | return node | |
|
745 | 752 | |
|
746 | 753 | |
|
747 | 754 | class TestAstTransformError(unittest.TestCase): |
@@ -762,7 +769,8 b' class StringRejector(ast.NodeTransformer):' | |||
|
762 | 769 | Used to verify that NodeTransformers can signal that a piece of code should |
|
763 | 770 | not be executed by throwing an InputRejected. |
|
764 | 771 | """ |
|
765 | ||
|
772 | ||
|
773 | #for python 3.7 and earlier | |
|
766 | 774 | def visit_Str(self, node): |
|
767 | 775 | raise InputRejected("test") |
|
768 | 776 |
@@ -384,6 +384,10 b' from IPython.testing.decorators import skipif' | |||
|
384 | 384 | class TokenizeFailureTest(unittest.TestCase): |
|
385 | 385 | """Tests related to https://github.com/ipython/ipython/issues/6864.""" |
|
386 | 386 | |
|
387 | # that appear to test that we are handling an exception that can be thrown | |
|
388 | # by the tokenizer due to a bug that seem to have been fixed in 3.8, though | |
|
389 | # I'm unsure if other sequences can make it raise this error. Let's just | |
|
390 | # skip in 3.8 for now | |
|
387 | 391 | @skipif(sys.version_info > (3,8)) |
|
388 | 392 | def testLogging(self): |
|
389 | 393 | message = "An unexpected error occurred while tokenizing input" |
General Comments 0
You need to be logged in to leave comments.
Login now