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