##// END OF EJS Templates
Some minimal typing and removal of allow-none
Matthias Bussonnier -
Show More
@@ -2550,7 +2550,7 b' class IPCompleter(Completer):'
2550 EvaluationContext(
2550 EvaluationContext(
2551 globals=self.global_namespace,
2551 globals=self.global_namespace,
2552 locals=self.namespace,
2552 locals=self.namespace,
2553 evaluation=self.evaluation,
2553 evaluation=self.evaluation, # type: ignore
2554 in_subscript=True,
2554 in_subscript=True,
2555 ),
2555 ),
2556 )
2556 )
@@ -53,13 +53,13 b' class DisplayFormatter(Configurable):'
53 else:
53 else:
54 formatter.enabled = False
54 formatter.enabled = False
55
55
56 ipython_display_formatter = ForwardDeclaredInstance("FormatterABC")
56 ipython_display_formatter = ForwardDeclaredInstance("FormatterABC") # type: ignore
57
57
58 @default("ipython_display_formatter")
58 @default("ipython_display_formatter")
59 def _default_formatter(self):
59 def _default_formatter(self):
60 return IPythonDisplayFormatter(parent=self)
60 return IPythonDisplayFormatter(parent=self)
61
61
62 mimebundle_formatter = ForwardDeclaredInstance("FormatterABC")
62 mimebundle_formatter = ForwardDeclaredInstance("FormatterABC") # type: ignore
63
63
64 @default("mimebundle_formatter")
64 @default("mimebundle_formatter")
65 def _default_mime_formatter(self):
65 def _default_mime_formatter(self):
@@ -489,8 +489,9 b' class HistoryManager(HistoryAccessor):'
489 input_hist_parsed = List([""])
489 input_hist_parsed = List([""])
490 input_hist_raw = List([""])
490 input_hist_raw = List([""])
491 # A list of directories visited during session
491 # A list of directories visited during session
492 dir_hist = List()
492 dir_hist: List = List()
493 @default('dir_hist')
493
494 @default("dir_hist")
494 def _dir_hist_default(self):
495 def _dir_hist_default(self):
495 try:
496 try:
496 return [Path.cwd()]
497 return [Path.cwd()]
@@ -514,8 +515,8 b' class HistoryManager(HistoryAccessor):'
514 "Values of 1 or less effectively disable caching."
515 "Values of 1 or less effectively disable caching."
515 ).tag(config=True)
516 ).tag(config=True)
516 # The input and output caches
517 # The input and output caches
517 db_input_cache = List()
518 db_input_cache: List = List()
518 db_output_cache = List()
519 db_output_cache: List = List()
519
520
520 # History saving in separate thread
521 # History saving in separate thread
521 save_thread = Instance('IPython.core.history.HistorySavingThread',
522 save_thread = Instance('IPython.core.history.HistorySavingThread',
@@ -526,10 +527,10 b' class HistoryManager(HistoryAccessor):'
526 # Variables used to store the three last inputs from the user. On each new
527 # Variables used to store the three last inputs from the user. On each new
527 # history update, we populate the user's namespace with these, shifted as
528 # history update, we populate the user's namespace with these, shifted as
528 # necessary.
529 # necessary.
529 _i00 = Unicode(u'')
530 _i00 = Unicode("")
530 _i = Unicode(u'')
531 _i = Unicode("")
531 _ii = Unicode(u'')
532 _ii = Unicode("")
532 _iii = Unicode(u'')
533 _iii = Unicode("")
533
534
534 # A regex matching all forms of the exit command, so that we don't store
535 # A regex matching all forms of the exit command, so that we don't store
535 # them in the history (it's annoying to rewind the first entry and land on
536 # them in the history (it's annoying to rewind the first entry and land on
@@ -314,11 +314,12 b' class InteractiveShell(SingletonConfigurable):'
314
314
315 _instance = None
315 _instance = None
316
316
317 ast_transformers = List([], help=
317 ast_transformers: List[ast.NodeTransformer] = List(
318 """
318 [],
319 help="""
319 A list of ast.NodeTransformer subclass instances, which will be applied
320 A list of ast.NodeTransformer subclass instances, which will be applied
320 to user input before code is run.
321 to user input before code is run.
321 """
322 """,
322 ).tag(config=True)
323 ).tag(config=True)
323
324
324 autocall = Enum((0,1,2), default_value=0, help=
325 autocall = Enum((0,1,2), default_value=0, help=
@@ -553,14 +554,20 b' class InteractiveShell(SingletonConfigurable):'
553 ).tag(config=True)
554 ).tag(config=True)
554
555
555 # Subcomponents of InteractiveShell
556 # Subcomponents of InteractiveShell
556 alias_manager = Instance('IPython.core.alias.AliasManager', allow_none=True)
557 alias_manager = Instance("IPython.core.alias.AliasManager", allow_none=True)
557 prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager', allow_none=True)
558 prefilter_manager = Instance(
558 builtin_trap = Instance('IPython.core.builtin_trap.BuiltinTrap', allow_none=True)
559 "IPython.core.prefilter.PrefilterManager", allow_none=True
559 display_trap = Instance('IPython.core.display_trap.DisplayTrap', allow_none=True)
560 )
560 extension_manager = Instance('IPython.core.extensions.ExtensionManager', allow_none=True)
561 builtin_trap = Instance("IPython.core.builtin_trap.BuiltinTrap")
561 payload_manager = Instance('IPython.core.payload.PayloadManager', allow_none=True)
562 display_trap = Instance("IPython.core.display_trap.DisplayTrap")
562 history_manager = Instance('IPython.core.history.HistoryAccessorBase', allow_none=True)
563 extension_manager = Instance(
563 magics_manager = Instance('IPython.core.magic.MagicsManager', allow_none=True)
564 "IPython.core.extensions.ExtensionManager", allow_none=True
565 )
566 payload_manager = Instance("IPython.core.payload.PayloadManager", allow_none=True)
567 history_manager = Instance(
568 "IPython.core.history.HistoryAccessorBase", allow_none=True
569 )
570 magics_manager = Instance("IPython.core.magic.MagicsManager")
564
571
565 profile_dir = Instance('IPython.core.application.ProfileDir', allow_none=True)
572 profile_dir = Instance('IPython.core.application.ProfileDir', allow_none=True)
566 @property
573 @property
@@ -1396,6 +1403,7 b' class InteractiveShell(SingletonConfigurable):'
1396 If new_session is True, a new history session will be opened.
1403 If new_session is True, a new history session will be opened.
1397 """
1404 """
1398 # Clear histories
1405 # Clear histories
1406 assert self.history_manager is not None
1399 self.history_manager.reset(new_session)
1407 self.history_manager.reset(new_session)
1400 # Reset counter used to index all histories
1408 # Reset counter used to index all histories
1401 if new_session:
1409 if new_session:
@@ -1482,6 +1490,7 b' class InteractiveShell(SingletonConfigurable):'
1482 except KeyError as e:
1490 except KeyError as e:
1483 raise NameError("name '%s' is not defined" % varname) from e
1491 raise NameError("name '%s' is not defined" % varname) from e
1484 # Also check in output history
1492 # Also check in output history
1493 assert self.history_manager is not None
1485 ns_refs.append(self.history_manager.output_hist)
1494 ns_refs.append(self.history_manager.output_hist)
1486 for ns in ns_refs:
1495 for ns in ns_refs:
1487 to_delete = [n for n, o in ns.items() if o is obj]
1496 to_delete = [n for n, o in ns.items() if o is obj]
@@ -1801,7 +1810,7 b' class InteractiveShell(SingletonConfigurable):'
1801 """Find an object and return a struct with info about it."""
1810 """Find an object and return a struct with info about it."""
1802 return self._ofind(oname, namespaces)
1811 return self._ofind(oname, namespaces)
1803
1812
1804 def _inspect(self, meth, oname, namespaces=None, **kw):
1813 def _inspect(self, meth, oname: str, namespaces=None, **kw):
1805 """Generic interface to the inspector system.
1814 """Generic interface to the inspector system.
1806
1815
1807 This function is meant to be called by pdef, pdoc & friends.
1816 This function is meant to be called by pdef, pdoc & friends.
@@ -2409,7 +2418,7 b' class InteractiveShell(SingletonConfigurable):'
2409 res = finder(magic_name)
2418 res = finder(magic_name)
2410 return res
2419 return res
2411
2420
2412 def run_line_magic(self, magic_name: str, line, _stack_depth=1):
2421 def run_line_magic(self, magic_name: str, line: str, _stack_depth=1):
2413 """Execute the given line magic.
2422 """Execute the given line magic.
2414
2423
2415 Parameters
2424 Parameters
@@ -3256,6 +3265,7 b' class InteractiveShell(SingletonConfigurable):'
3256
3265
3257 # Store raw and processed history
3266 # Store raw and processed history
3258 if store_history:
3267 if store_history:
3268 assert self.history_manager is not None
3259 self.history_manager.store_inputs(self.execution_count, cell, raw_cell)
3269 self.history_manager.store_inputs(self.execution_count, cell, raw_cell)
3260 if not silent:
3270 if not silent:
3261 self.logger.log(cell, raw_cell)
3271 self.logger.log(cell, raw_cell)
@@ -3272,8 +3282,6 b' class InteractiveShell(SingletonConfigurable):'
3272 # compiler
3282 # compiler
3273 compiler = self.compile if shell_futures else self.compiler_class()
3283 compiler = self.compile if shell_futures else self.compiler_class()
3274
3284
3275 _run_async = False
3276
3277 with self.builtin_trap:
3285 with self.builtin_trap:
3278 cell_name = compiler.cache(cell, self.execution_count, raw_code=raw_cell)
3286 cell_name = compiler.cache(cell, self.execution_count, raw_code=raw_cell)
3279
3287
@@ -178,7 +178,17 b' transforming:'
178 __skip_doctest__ = True
178 __skip_doctest__ = True
179
179
180
180
181 from ast import NodeTransformer, Store, Load, Name, Expr, Assign, Module, Import, ImportFrom
181 from ast import (
182 NodeTransformer,
183 Store,
184 Load,
185 Name,
186 Expr,
187 Assign,
188 Module,
189 Import,
190 ImportFrom,
191 )
182 import ast
192 import ast
183 import copy
193 import copy
184
194
@@ -231,13 +241,13 b' class Mangler(NodeTransformer):'
231 self.log("Not mangling function arg", arg.arg)
241 self.log("Not mangling function arg", arg.arg)
232 return self.generic_visit(node)
242 return self.generic_visit(node)
233
243
234 def visit_ImportFrom(self, node:ImportFrom):
244 def visit_ImportFrom(self, node: ImportFrom):
235 return self._visit_Import_and_ImportFrom(node)
245 return self._visit_Import_and_ImportFrom(node)
236
246
237 def visit_Import(self, node:Import):
247 def visit_Import(self, node: Import):
238 return self._visit_Import_and_ImportFrom(node)
248 return self._visit_Import_and_ImportFrom(node)
239
249
240 def _visit_Import_and_ImportFrom(self, node:Union[Import, ImportFrom]):
250 def _visit_Import_and_ImportFrom(self, node: Union[Import, ImportFrom]):
241 for alias in node.names:
251 for alias in node.names:
242 asname = alias.name if alias.asname is None else alias.asname
252 asname = alias.name if alias.asname is None else alias.asname
243 if self.predicate(asname):
253 if self.predicate(asname):
@@ -86,7 +86,7 b' class ScriptMagics(Magics):'
86 """
86 """
87 )
87 )
88
88
89 script_magics = List(
89 script_magics: List = List(
90 help="""Extra script cell magics to define
90 help="""Extra script cell magics to define
91
91
92 This generates simple wrappers of `%%script foo` as `%%foo`.
92 This generates simple wrappers of `%%script foo` as `%%foo`.
@@ -95,6 +95,7 b' class ScriptMagics(Magics):'
95 specify them in script_paths
95 specify them in script_paths
96 """,
96 """,
97 ).tag(config=True)
97 ).tag(config=True)
98
98 @default('script_magics')
99 @default('script_magics')
99 def _script_magics_default(self):
100 def _script_magics_default(self):
100 """default to a common list of programs"""
101 """default to a common list of programs"""
@@ -524,11 +524,14 b' class AutocallChecker(PrefilterChecker):'
524
524
525
525
526 class PrefilterHandler(Configurable):
526 class PrefilterHandler(Configurable):
527
527 handler_name = Unicode("normal")
528 handler_name = Unicode('normal')
528 esc_strings: List = List([])
529 esc_strings = List([])
529 shell = Instance(
530 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
530 "IPython.core.interactiveshell.InteractiveShellABC", allow_none=True
531 prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager', allow_none=True)
531 )
532 prefilter_manager = Instance(
533 "IPython.core.prefilter.PrefilterManager", allow_none=True
534 )
532
535
533 def __init__(self, shell=None, prefilter_manager=None, **kwargs):
536 def __init__(self, shell=None, prefilter_manager=None, **kwargs):
534 super(PrefilterHandler, self).__init__(
537 super(PrefilterHandler, self).__init__(
General Comments 0
You need to be logged in to leave comments. Login now