##// END OF EJS Templates
Merge pull request #12093 from yangyangxcf/catch_memory_error...
Matthias Bussonnier -
r25439:53490e42 merge
parent child Browse files
Show More
@@ -146,20 +146,20 b' def _should_be_async(cell: str) -> bool:'
146
146
147 If it works, assume it should be async. Otherwise Return False.
147 If it works, assume it should be async. Otherwise Return False.
148
148
149 Not handled yet: If the block of code has a return statement as the top
149 Not handled yet: If the block of code has a return statement as the top
150 level, it will be seen as async. This is a know limitation.
150 level, it will be seen as async. This is a know limitation.
151 """
151 """
152 if sys.version_info > (3, 8):
152 if sys.version_info > (3, 8):
153 try:
153 try:
154 code = compile(cell, "<>", "exec", flags=getattr(ast,'PyCF_ALLOW_TOP_LEVEL_AWAIT', 0x0))
154 code = compile(cell, "<>", "exec", flags=getattr(ast,'PyCF_ALLOW_TOP_LEVEL_AWAIT', 0x0))
155 return inspect.CO_COROUTINE & code.co_flags == inspect.CO_COROUTINE
155 return inspect.CO_COROUTINE & code.co_flags == inspect.CO_COROUTINE
156 except SyntaxError:
156 except (SyntaxError, MemoryError):
157 return False
157 return False
158 try:
158 try:
159 # we can't limit ourself to ast.parse, as it __accepts__ to parse on
159 # we can't limit ourself to ast.parse, as it __accepts__ to parse on
160 # 3.7+, but just does not _compile_
160 # 3.7+, but just does not _compile_
161 code = compile(cell, "<>", "exec")
161 code = compile(cell, "<>", "exec")
162 except SyntaxError:
162 except (SyntaxError, MemoryError):
163 try:
163 try:
164 parse_tree = _async_parse_cell(cell)
164 parse_tree = _async_parse_cell(cell)
165
165
@@ -167,7 +167,7 b' def _should_be_async(cell: str) -> bool:'
167 v = _AsyncSyntaxErrorVisitor()
167 v = _AsyncSyntaxErrorVisitor()
168 v.visit(parse_tree)
168 v.visit(parse_tree)
169
169
170 except SyntaxError:
170 except (SyntaxError, MemoryError):
171 return False
171 return False
172 return True
172 return True
173 return False
173 return False
@@ -276,6 +276,10 b' class AsyncTest(TestCase):'
276 """
276 """
277 )
277 )
278
278
279 def test_memory_error(self):
280 with self.assertRaises(MemoryError):
281 iprc("(" * 200 + ")" * 200)
282
279 @skip_without('curio')
283 @skip_without('curio')
280 def test_autoawait_curio(self):
284 def test_autoawait_curio(self):
281 iprc("%autoawait curio")
285 iprc("%autoawait curio")
@@ -253,6 +253,13 b' bar()'
253 ip.showsyntaxerror()
253 ip.showsyntaxerror()
254
254
255
255
256 class MemoryErrorTest(unittest.TestCase):
257 def test_memoryerror(self):
258 memoryerror_code = "(" * 200 + ")" * 200
259 with tt.AssertPrints("MemoryError"):
260 ip.run_cell(memoryerror_code)
261
262
256 class Python3ChainedExceptionsTest(unittest.TestCase):
263 class Python3ChainedExceptionsTest(unittest.TestCase):
257 DIRECT_CAUSE_ERROR_CODE = """
264 DIRECT_CAUSE_ERROR_CODE = """
258 try:
265 try:
General Comments 0
You need to be logged in to leave comments. Login now