aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/ipython/py3/IPython/terminal/embed.py
diff options
context:
space:
mode:
authorrobot-contrib <robot-contrib@yandex-team.ru>2022-05-18 00:43:36 +0300
committerrobot-contrib <robot-contrib@yandex-team.ru>2022-05-18 00:43:36 +0300
commit9e5f436a8b2a27bcc7802e443ea3ef3e41a82a75 (patch)
tree78b522cab9f76336e62064d4d8ff7c897659b20e /contrib/python/ipython/py3/IPython/terminal/embed.py
parent8113a823ffca6451bb5ff8f0334560885a939a24 (diff)
downloadydb-9e5f436a8b2a27bcc7802e443ea3ef3e41a82a75.tar.gz
Update contrib/python/ipython/py3 to 8.3.0
ref:e84342d4d30476f9148137f37fd0c6405fd36f55
Diffstat (limited to 'contrib/python/ipython/py3/IPython/terminal/embed.py')
-rw-r--r--contrib/python/ipython/py3/IPython/terminal/embed.py91
1 files changed, 51 insertions, 40 deletions
diff --git a/contrib/python/ipython/py3/IPython/terminal/embed.py b/contrib/python/ipython/py3/IPython/terminal/embed.py
index 188844fadd..85e76d5558 100644
--- a/contrib/python/ipython/py3/IPython/terminal/embed.py
+++ b/contrib/python/ipython/py3/IPython/terminal/embed.py
@@ -19,6 +19,8 @@ from IPython.terminal.ipapp import load_default_config
from traitlets import Bool, CBool, Unicode
from IPython.utils.io import ask_yes_no
+from typing import Set
+
class KillEmbedded(Exception):pass
# kept for backward compatibility as IPython 6 was released with
@@ -47,7 +49,6 @@ class EmbeddedMagics(Magics):
you may then kill it and the program will then continue to run without
the interactive shell interfering again.
-
Kill Instance Option:
If for some reasons you need to kill the location where the instance
@@ -106,6 +107,14 @@ class EmbeddedMagics(Magics):
self.shell.ask_exit()
+class _Sentinel:
+ def __init__(self, repr):
+ assert isinstance(repr, str)
+ self.repr = repr
+
+ def __repr__(self):
+ return repr
+
class InteractiveShellEmbed(TerminalInteractiveShell):
@@ -123,17 +132,17 @@ class InteractiveShellEmbed(TerminalInteractiveShell):
help="Automatically set the terminal title"
).tag(config=True)
- _inactive_locations = set()
+ _inactive_locations: Set[str] = set()
+
+ def _disable_init_location(self):
+ """Disable the current Instance creation location"""
+ InteractiveShellEmbed._inactive_locations.add(self._init_location_id)
@property
def embedded_active(self):
return (self._call_location_id not in InteractiveShellEmbed._inactive_locations)\
and (self._init_location_id not in InteractiveShellEmbed._inactive_locations)
- def _disable_init_location(self):
- """Disable the current Instance creation location"""
- InteractiveShellEmbed._inactive_locations.add(self._init_location_id)
-
@embedded_active.setter
def embedded_active(self, value):
if value:
@@ -146,9 +155,9 @@ class InteractiveShellEmbed(TerminalInteractiveShell):
self._call_location_id)
def __init__(self, **kw):
- if kw.get('user_global_ns', None) is not None:
- raise DeprecationWarning(
- "Key word argument `user_global_ns` has been replaced by `user_module` since IPython 4.0.")
+ assert (
+ "user_global_ns" not in kw
+ ), "Key word argument `user_global_ns` has been replaced by `user_module` since IPython 4.0."
clid = kw.pop('_init_location_id', None)
if not clid:
@@ -174,8 +183,16 @@ class InteractiveShellEmbed(TerminalInteractiveShell):
super(InteractiveShellEmbed, self).init_magics()
self.register_magics(EmbeddedMagics)
- def __call__(self, header='', local_ns=None, module=None, dummy=None,
- stack_depth=1, global_ns=None, compile_flags=None, **kw):
+ def __call__(
+ self,
+ header="",
+ local_ns=None,
+ module=None,
+ dummy=None,
+ stack_depth=1,
+ compile_flags=None,
+ **kw
+ ):
"""Activate the interactive interpreter.
__call__(self,header='',local_ns=None,module=None,dummy=None) -> Start
@@ -225,8 +242,9 @@ class InteractiveShellEmbed(TerminalInteractiveShell):
# Call the embedding code with a stack depth of 1 so it can skip over
# our call and get the original caller's namespaces.
- self.mainloop(local_ns, module, stack_depth=stack_depth,
- global_ns=global_ns, compile_flags=compile_flags)
+ self.mainloop(
+ local_ns, module, stack_depth=stack_depth, compile_flags=compile_flags
+ )
self.banner2 = self.old_banner2
@@ -236,40 +254,35 @@ class InteractiveShellEmbed(TerminalInteractiveShell):
if self.should_raise:
raise KillEmbedded('Embedded IPython raising error, as user requested.')
-
- def mainloop(self, local_ns=None, module=None, stack_depth=0,
- display_banner=None, global_ns=None, compile_flags=None):
+ def mainloop(
+ self,
+ local_ns=None,
+ module=None,
+ stack_depth=0,
+ compile_flags=None,
+ ):
"""Embeds IPython into a running python program.
Parameters
----------
-
local_ns, module
- Working local namespace (a dict) and module (a module or similar
- object). If given as None, they are automatically taken from the scope
- where the shell was called, so that program variables become visible.
-
+ Working local namespace (a dict) and module (a module or similar
+ object). If given as None, they are automatically taken from the scope
+ where the shell was called, so that program variables become visible.
stack_depth : int
- How many levels in the stack to go to looking for namespaces (when
- local_ns or module is None). This allows an intermediate caller to
- make sure that this function gets the namespace from the intended
- level in the stack. By default (0) it will get its locals and globals
- from the immediate caller.
-
+ How many levels in the stack to go to looking for namespaces (when
+ local_ns or module is None). This allows an intermediate caller to
+ make sure that this function gets the namespace from the intended
+ level in the stack. By default (0) it will get its locals and globals
+ from the immediate caller.
compile_flags
- A bit field identifying the __future__ features
- that are enabled, as passed to the builtin :func:`compile` function.
- If given as None, they are automatically taken from the scope where
- the shell was called.
+ A bit field identifying the __future__ features
+ that are enabled, as passed to the builtin :func:`compile` function.
+ If given as None, they are automatically taken from the scope where
+ the shell was called.
"""
- if (global_ns is not None) and (module is None):
- raise DeprecationWarning("'global_ns' keyword argument is deprecated, and has been removed in IPython 5.0 use `module` keyword argument instead.")
-
- if (display_banner is not None):
- warnings.warn("The display_banner parameter is deprecated since IPython 4.0", DeprecationWarning)
-
# Get locals and globals from caller
if ((local_ns is None or module is None or compile_flags is None)
and self.default_user_namespaces):
@@ -334,7 +347,7 @@ class InteractiveShellEmbed(TerminalInteractiveShell):
self.compile.flags = orig_compile_flags
-def embed(**kwargs):
+def embed(*, header="", compile_flags=None, **kwargs):
"""Call this to embed IPython at the current point in your program.
The first invocation of this will create an :class:`InteractiveShellEmbed`
@@ -360,8 +373,6 @@ def embed(**kwargs):
config argument.
"""
config = kwargs.get('config')
- header = kwargs.pop('header', u'')
- compile_flags = kwargs.pop('compile_flags', None)
if config is None:
config = load_default_config()
config.InteractiveShellEmbed = config.TerminalInteractiveShell