From a0dffa8ed9dd690bdda5bd039a47d2b1062c89bc 2019-02-07 03:26:17 From: Matthias Bussonnier Date: 2019-02-07 03:26:17 Subject: [PATCH] Attemt to fix ast transformer now that Num and Str atr the same Constant ast node Also fix soem new sytax warnings. --- diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index 83ff11b..7be1273 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -616,7 +616,8 @@ class Negator(ast.NodeTransformer): if sys.version_info > (3,8): def visit_Constant(self, node): - return self.visit_Num(node) + if isinstance(node.value, int): + return self.visit_Num(node) class TestAstTransform(unittest.TestCase): def setUp(self): @@ -687,7 +688,8 @@ class IntegerWrapper(ast.NodeTransformer): if sys.version_info > (3,8): def visit_Constant(self, node): - return self.visit_Num(node) + if isinstance(node.value, int): + return self.visit_Num(node) class TestAstTransform2(unittest.TestCase): @@ -735,7 +737,8 @@ class ErrorTransformer(ast.NodeTransformer): if sys.version_info > (3,8): def visit_Constant(self, node): - return self.visit_Num(node) + if isinstance(node.value, int): + return self.visit_Num(node) class TestAstTransformError(unittest.TestCase): @@ -760,6 +763,11 @@ class StringRejector(ast.NodeTransformer): def visit_Str(self, node): raise InputRejected("test") + # 3.8 only + def visit_Constant(self, node): + if isinstance(node.value, str): + raise InputRejected("test") + class TestAstTransformInputRejection(unittest.TestCase): diff --git a/IPython/terminal/ptutils.py b/IPython/terminal/ptutils.py index bc22f8e..4f21cb0 100644 --- a/IPython/terminal/ptutils.py +++ b/IPython/terminal/ptutils.py @@ -53,7 +53,7 @@ def _elide(string, *, min_elide=30): def _adjust_completion_text_based_on_context(text, body, offset): - if text.endswith('=') and len(body) > offset and body[offset] is '=': + if text.endswith('=') and len(body) > offset and body[offset] == '=': return text[:-1] else: return text