##// END OF EJS Templates
some typing
Matthias Bussonnier -
Show More
@@ -82,14 +82,17 b' from warnings import warn'
82 82 from logging import error
83 83 import IPython.core.hooks
84 84
85 from typing import List as ListType, Tuple, Optional
86 from ast import AST
85 from typing import List as ListType, Tuple, Optional, Callable
86 from ast import AST, stmt
87
87 88
88 89 # NoOpContext is deprecated, but ipykernel imports it from here.
89 90 # See https://github.com/ipython/ipykernel/issues/157
90 91 # (2016, let's try to remove than in IPython 8.0)
91 92 from IPython.utils.contexts import NoOpContext
92 93
94 sphinxify: Optional[Callable]
95
93 96 try:
94 97 import docrepr.sphinxify as sphx
95 98
@@ -207,14 +210,20 b' def _ast_asyncify(cell:str, wrapper_name:str) -> ast.Module:'
207 210 is updated only on `local()` calls.
208 211 """
209 212
210 from ast import Expr, Await, Return
213 from ast import Expr, Await, Return, stmt, FunctionDef, Try, AsyncFunctionDef
211 214 if sys.version_info >= (3,8):
212 215 return ast.parse(cell)
213 216 tree = ast.parse(_asyncify(cell))
214 217
215 218 function_def = tree.body[0]
219 if sys.version_info > (3, 8):
220 assert isinstance(function_def, FunctionDef), function_def
221 else:
222 assert isinstance(function_def, (FunctionDef, AsyncFunctionDef)), function_def
223
216 224 function_def.name = wrapper_name
217 225 try_block = function_def.body[0]
226 assert isinstance(try_block, Try)
218 227 lastexpr = try_block.body[-1]
219 228 if isinstance(lastexpr, (Expr, Await)):
220 229 try_block.body[-1] = Return(lastexpr.value)
@@ -312,7 +321,7 b' class ExecutionResult(object):'
312 321 """
313 322 execution_count = None
314 323 error_before_exec = None
315 error_in_exec = None
324 error_in_exec: Optional[BaseException] = None
316 325 info = None
317 326 result = None
318 327
@@ -3278,8 +3287,14 b' class InteractiveShell(SingletonConfigurable):'
3278 3287 ast.fix_missing_locations(node)
3279 3288 return node
3280 3289
3281 async def run_ast_nodes(self, nodelist:ListType[AST], cell_name:str, interactivity='last_expr',
3282 compiler=compile, result=None):
3290 async def run_ast_nodes(
3291 self,
3292 nodelist: ListType[stmt],
3293 cell_name: str,
3294 interactivity="last_expr",
3295 compiler=compile,
3296 result=None,
3297 ):
3283 3298 """Run a sequence of AST nodes. The execution mode depends on the
3284 3299 interactivity parameter.
3285 3300
@@ -3318,6 +3333,7 b' class InteractiveShell(SingletonConfigurable):'
3318 3333 if not nodelist:
3319 3334 return
3320 3335
3336
3321 3337 if interactivity == 'last_expr_or_assign':
3322 3338 if isinstance(nodelist[-1], _assign_nodes):
3323 3339 asg = nodelist[-1]
@@ -1,4 +1,4 b''
1 1 [mypy]
2 python_version = 3.6
2 python_version = 3.8
3 3 ignore_missing_imports = True
4 4 follow_imports = silent
General Comments 0
You need to be logged in to leave comments. Login now