##// END OF EJS Templates
Merge pull request #11593 from Carreau/ast-38...
Matthias Bussonnier -
r24935:542cc5a4 merge
parent child Browse files
Show More
@@ -67,6 +67,9 b' matrix:'
67 67 - python: "3.7"
68 68 dist: xenial
69 69 sudo: true
70 - python: "3.8-dev"
71 dist: xenial
72 sudo: true
70 73 - python: "3.7-dev"
71 74 dist: xenial
72 75 sudo: true
@@ -107,6 +107,14 b' class ProvisionalWarning(DeprecationWarning):'
107 107 """
108 108 pass
109 109
110 if sys.version_info > (3,8):
111 from ast import Module
112 else :
113 # mock the new API, ignore second argument
114 # see https://github.com/ipython/ipython/issues/11590
115 from ast import Module as OriginalModule
116 Module = lambda nodelist, type_ignores: OriginalModule(nodelist)
117
110 118 if sys.version_info > (3,6):
111 119 _assign_nodes = (ast.AugAssign, ast.AnnAssign, ast.Assign)
112 120 _single_targets_nodes = (ast.AugAssign, ast.AnnAssign)
@@ -3188,15 +3196,15 b' class InteractiveShell(SingletonConfigurable):'
3188 3196 if _async:
3189 3197 # If interactivity is async the semantics of run_code are
3190 3198 # completely different Skip usual machinery.
3191 mod = ast.Module(nodelist)
3192 async_wrapper_code = compiler(mod, 'cell_name', 'exec')
3199 mod = Module(nodelist, [])
3200 async_wrapper_code = compiler(mod, cell_name, 'exec')
3193 3201 exec(async_wrapper_code, self.user_global_ns, self.user_ns)
3194 3202 async_code = removed_co_newlocals(self.user_ns.pop('async-def-wrapper')).__code__
3195 3203 if (yield from self.run_code(async_code, result, async_=True)):
3196 3204 return True
3197 3205 else:
3198 3206 for i, node in enumerate(to_run_exec):
3199 mod = ast.Module([node])
3207 mod = Module([node], [])
3200 3208 code = compiler(mod, cell_name, "exec")
3201 3209 if (yield from self.run_code(code, result)):
3202 3210 return True
@@ -609,10 +609,18 b' class TestModules(tt.TempFileMixin, unittest.TestCase):'
609 609
610 610 class Negator(ast.NodeTransformer):
611 611 """Negates all number literals in an AST."""
612
613 # for python 3.7 and earlier
612 614 def visit_Num(self, node):
613 615 node.n = -node.n
614 616 return node
615 617
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
623
616 624 class TestAstTransform(unittest.TestCase):
617 625 def setUp(self):
618 626 self.negator = Negator()
@@ -674,12 +682,23 b' class TestAstTransform(unittest.TestCase):'
674 682
675 683 class IntegerWrapper(ast.NodeTransformer):
676 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
677 689 def visit_Num(self, node):
678 690 if isinstance(node.n, int):
679 691 return ast.Call(func=ast.Name(id='Integer', ctx=ast.Load()),
680 692 args=[node], keywords=[])
681 693 return node
682 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
700
701
683 702 class TestAstTransform2(unittest.TestCase):
684 703 def setUp(self):
685 704 self.intwrapper = IntegerWrapper()
@@ -720,9 +739,18 b' class TestAstTransform2(unittest.TestCase):'
720 739
721 740 class ErrorTransformer(ast.NodeTransformer):
722 741 """Throws an error when it sees a number."""
742
743 # for Python 3.7 and earlier
723 744 def visit_Num(self, node):
724 745 raise ValueError("test")
725 746
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
752
753
726 754 class TestAstTransformError(unittest.TestCase):
727 755 def test_unregistering(self):
728 756 err_transformer = ErrorTransformer()
@@ -741,10 +769,17 b' class StringRejector(ast.NodeTransformer):'
741 769 Used to verify that NodeTransformers can signal that a piece of code should
742 770 not be executed by throwing an InputRejected.
743 771 """
744
772
773 #for python 3.7 and earlier
745 774 def visit_Str(self, node):
746 775 raise InputRejected("test")
747 776
777 # 3.8 only
778 def visit_Constant(self, node):
779 if isinstance(node.value, str):
780 raise InputRejected("test")
781 return node
782
748 783
749 784 class TestAstTransformInputRejection(unittest.TestCase):
750 785
@@ -379,10 +379,16 b' def test_handlers():'
379 379 handler(*sys.exc_info())
380 380 buff.write('')
381 381
382 from IPython.testing.decorators import skipif
382 383
383 384 class TokenizeFailureTest(unittest.TestCase):
384 385 """Tests related to https://github.com/ipython/ipython/issues/6864."""
385 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
391 @skipif(sys.version_info > (3,8))
386 392 def testLogging(self):
387 393 message = "An unexpected error occurred while tokenizing input"
388 394 cell = 'raise ValueError("""a\nb""")'
@@ -53,7 +53,7 b' def _elide(string, *, min_elide=30):'
53 53
54 54
55 55 def _adjust_completion_text_based_on_context(text, body, offset):
56 if text.endswith('=') and len(body) > offset and body[offset] is '=':
56 if text.endswith('=') and len(body) > offset and body[offset] == '=':
57 57 return text[:-1]
58 58 else:
59 59 return text
General Comments 0
You need to be logged in to leave comments. Login now