summaryrefslogtreecommitdiffstats
path: root/contrib/python/ipython/py3/IPython/core/interactiveshell.py
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/python/ipython/py3/IPython/core/interactiveshell.py')
-rw-r--r--contrib/python/ipython/py3/IPython/core/interactiveshell.py73
1 files changed, 49 insertions, 24 deletions
diff --git a/contrib/python/ipython/py3/IPython/core/interactiveshell.py b/contrib/python/ipython/py3/IPython/core/interactiveshell.py
index fef5ddc949b..12c120625b2 100644
--- a/contrib/python/ipython/py3/IPython/core/interactiveshell.py
+++ b/contrib/python/ipython/py3/IPython/core/interactiveshell.py
@@ -47,16 +47,29 @@ except ModuleNotFoundError:
def __init__(self, path):
pass
- def get(self, key, default):
+ def get(self, key, default=None):
warn(
- f"using {key} requires you to install the `pickleshare` library.",
+ f"This is now an optional IPython functionality, using {key} requires you to install the `pickleshare` library.",
stacklevel=2,
)
return default
+ def __getitem__(self, key):
+ warn(
+ f"This is now an optional IPython functionality, using {key} requires you to install the `pickleshare` library.",
+ stacklevel=2,
+ )
+ return None
+
def __setitem__(self, key, value):
warn(
- f"using {key} requires you to install the `pickleshare` library.",
+ f"This is now an optional IPython functionality, setting {key} requires you to install the `pickleshare` library.",
+ stacklevel=2,
+ )
+
+ def __delitem__(self, key):
+ warn(
+ f"This is now an optional IPython functionality, deleting {key} requires you to install the `pickleshare` library.",
stacklevel=2,
)
@@ -268,13 +281,14 @@ class ExecutionInfo(object):
)
-class ExecutionResult(object):
+class ExecutionResult:
"""The result of a call to :meth:`InteractiveShell.run_cell`
Stores information about what took place.
"""
- execution_count = None
- error_before_exec = None
+
+ execution_count: Optional[int] = None
+ error_before_exec: Optional[bool] = None
error_in_exec: Optional[BaseException] = None
info = None
result = None
@@ -314,11 +328,12 @@ class InteractiveShell(SingletonConfigurable):
_instance = None
- ast_transformers = List([], help=
- """
+ ast_transformers: List[ast.NodeTransformer] = List(
+ [],
+ help="""
A list of ast.NodeTransformer subclass instances, which will be applied
to user input before code is run.
- """
+ """,
).tag(config=True)
autocall = Enum((0,1,2), default_value=0, help=
@@ -463,7 +478,8 @@ class InteractiveShell(SingletonConfigurable):
def input_transformers_cleanup(self):
return self.input_transformer_manager.cleanup_transforms
- input_transformers_post = List([],
+ input_transformers_post: List = List(
+ [],
help="A list of string input transformers, to be applied after IPython's "
"own input transformations."
)
@@ -553,14 +569,20 @@ class InteractiveShell(SingletonConfigurable):
).tag(config=True)
# Subcomponents of InteractiveShell
- alias_manager = Instance('IPython.core.alias.AliasManager', allow_none=True)
- prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager', allow_none=True)
- builtin_trap = Instance('IPython.core.builtin_trap.BuiltinTrap', allow_none=True)
- display_trap = Instance('IPython.core.display_trap.DisplayTrap', allow_none=True)
- extension_manager = Instance('IPython.core.extensions.ExtensionManager', allow_none=True)
- payload_manager = Instance('IPython.core.payload.PayloadManager', allow_none=True)
- history_manager = Instance('IPython.core.history.HistoryAccessorBase', allow_none=True)
- magics_manager = Instance('IPython.core.magic.MagicsManager', allow_none=True)
+ alias_manager = Instance("IPython.core.alias.AliasManager", allow_none=True)
+ prefilter_manager = Instance(
+ "IPython.core.prefilter.PrefilterManager", allow_none=True
+ )
+ builtin_trap = Instance("IPython.core.builtin_trap.BuiltinTrap")
+ display_trap = Instance("IPython.core.display_trap.DisplayTrap")
+ extension_manager = Instance(
+ "IPython.core.extensions.ExtensionManager", allow_none=True
+ )
+ payload_manager = Instance("IPython.core.payload.PayloadManager", allow_none=True)
+ history_manager = Instance(
+ "IPython.core.history.HistoryAccessorBase", allow_none=True
+ )
+ magics_manager = Instance("IPython.core.magic.MagicsManager")
profile_dir = Instance('IPython.core.application.ProfileDir', allow_none=True)
@property
@@ -1396,6 +1418,7 @@ class InteractiveShell(SingletonConfigurable):
If new_session is True, a new history session will be opened.
"""
# Clear histories
+ assert self.history_manager is not None
self.history_manager.reset(new_session)
# Reset counter used to index all histories
if new_session:
@@ -1482,6 +1505,7 @@ class InteractiveShell(SingletonConfigurable):
except KeyError as e:
raise NameError("name '%s' is not defined" % varname) from e
# Also check in output history
+ assert self.history_manager is not None
ns_refs.append(self.history_manager.output_hist)
for ns in ns_refs:
to_delete = [n for n, o in ns.items() if o is obj]
@@ -1801,7 +1825,7 @@ class InteractiveShell(SingletonConfigurable):
"""Find an object and return a struct with info about it."""
return self._ofind(oname, namespaces)
- def _inspect(self, meth, oname, namespaces=None, **kw):
+ def _inspect(self, meth, oname: str, namespaces=None, **kw):
"""Generic interface to the inspector system.
This function is meant to be called by pdef, pdoc & friends.
@@ -2409,7 +2433,7 @@ class InteractiveShell(SingletonConfigurable):
res = finder(magic_name)
return res
- def run_line_magic(self, magic_name: str, line, _stack_depth=1):
+ def run_line_magic(self, magic_name: str, line: str, _stack_depth=1):
"""Execute the given line magic.
Parameters
@@ -3256,6 +3280,7 @@ class InteractiveShell(SingletonConfigurable):
# Store raw and processed history
if store_history:
+ assert self.history_manager is not None
self.history_manager.store_inputs(self.execution_count, cell, raw_cell)
if not silent:
self.logger.log(cell, raw_cell)
@@ -3272,8 +3297,6 @@ class InteractiveShell(SingletonConfigurable):
# compiler
compiler = self.compile if shell_futures else self.compiler_class()
- _run_async = False
-
with self.builtin_trap:
cell_name = compiler.cache(cell, self.execution_count, raw_code=raw_cell)
@@ -3319,6 +3342,7 @@ class InteractiveShell(SingletonConfigurable):
self.displayhook.exec_result = None
if store_history:
+ assert self.history_manager is not None
# Write output to the database. Does nothing unless
# history output logging is enabled.
self.history_manager.store_output(self.execution_count)
@@ -3630,8 +3654,6 @@ class InteractiveShell(SingletonConfigurable):
make sense in all contexts, for example a terminal ipython can't
display figures inline.
"""
- from matplotlib_inline.backend_inline import configure_inline_support
-
from IPython.core import pylabtools as pt
gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
@@ -3646,6 +3668,9 @@ class InteractiveShell(SingletonConfigurable):
gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
pt.activate_matplotlib(backend)
+
+ from matplotlib_inline.backend_inline import configure_inline_support
+
configure_inline_support(self, backend)
# Now we must activate the gui pylab wants to use, and fix %run to take