From 357c0131414f2f403c444e7025234fba2f7d7edb 2019-02-18 19:55:29 From: Matthias Bussonnier Date: 2019-02-18 19:55:29 Subject: [PATCH] comment why the changes and for which python version --- diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index a995633..1c05653 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -610,15 +610,16 @@ class TestModules(tt.TempFileMixin, unittest.TestCase): class Negator(ast.NodeTransformer): """Negates all number literals in an AST.""" + # for python 3.7 and earlier def visit_Num(self, node): node.n = -node.n return node - if sys.version_info > (3,8): - def visit_Constant(self, node): - if isinstance(node.value, int): - return self.visit_Num(node) - return node + # for python 3.8+ + def visit_Constant(self, node): + if isinstance(node.value, int): + return self.visit_Num(node) + return node class TestAstTransform(unittest.TestCase): def setUp(self): @@ -681,17 +682,21 @@ class TestAstTransform(unittest.TestCase): class IntegerWrapper(ast.NodeTransformer): """Wraps all integers in a call to Integer()""" + + # for Python 3.7 and earlier + + # for Python 3.7 and earlier def visit_Num(self, node): if isinstance(node.n, int): return ast.Call(func=ast.Name(id='Integer', ctx=ast.Load()), args=[node], keywords=[]) return node - if sys.version_info > (3,8): - def visit_Constant(self, node): - if isinstance(node.value, int): - return self.visit_Num(node) - return node + # For Python 3.8+ + def visit_Constant(self, node): + if isinstance(node.value, int): + return self.visit_Num(node) + return node class TestAstTransform2(unittest.TestCase): @@ -734,14 +739,16 @@ class TestAstTransform2(unittest.TestCase): class ErrorTransformer(ast.NodeTransformer): """Throws an error when it sees a number.""" + + # for Python 3.7 and earlier def visit_Num(self, node): raise ValueError("test") - if sys.version_info > (3,8): - def visit_Constant(self, node): - if isinstance(node.value, int): - return self.visit_Num(node) - return node + # for Python 3.8+ + def visit_Constant(self, node): + if isinstance(node.value, int): + return self.visit_Num(node) + return node class TestAstTransformError(unittest.TestCase): @@ -762,7 +769,8 @@ class StringRejector(ast.NodeTransformer): Used to verify that NodeTransformers can signal that a piece of code should not be executed by throwing an InputRejected. """ - + + #for python 3.7 and earlier def visit_Str(self, node): raise InputRejected("test") diff --git a/IPython/core/tests/test_ultratb.py b/IPython/core/tests/test_ultratb.py index 1af31c3..536a4db 100644 --- a/IPython/core/tests/test_ultratb.py +++ b/IPython/core/tests/test_ultratb.py @@ -384,6 +384,10 @@ from IPython.testing.decorators import skipif class TokenizeFailureTest(unittest.TestCase): """Tests related to https://github.com/ipython/ipython/issues/6864.""" + # that appear to test that we are handling an exception that can be thrown + # by the tokenizer due to a bug that seem to have been fixed in 3.8, though + # I'm unsure if other sequences can make it raise this error. Let's just + # skip in 3.8 for now @skipif(sys.version_info > (3,8)) def testLogging(self): message = "An unexpected error occurred while tokenizing input"