aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/ipython/py3/IPython/core
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-02-15 11:42:00 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-02-15 11:57:41 +0300
commit0de9b4a47867a2f539f7f5f02078bc353f6fb044 (patch)
treee60d2593309655d66f72d1a61ea42980313379ca /contrib/python/ipython/py3/IPython/core
parent6ecbb0cbb39049f5c9166871ffd217e60d3494bf (diff)
downloadydb-0de9b4a47867a2f539f7f5f02078bc353f6fb044.tar.gz
Intermediate changes
Diffstat (limited to 'contrib/python/ipython/py3/IPython/core')
-rw-r--r--contrib/python/ipython/py3/IPython/core/alias.py24
-rw-r--r--contrib/python/ipython/py3/IPython/core/application.py4
-rw-r--r--contrib/python/ipython/py3/IPython/core/debugger.py7
-rw-r--r--contrib/python/ipython/py3/IPython/core/excolors.py226
-rw-r--r--contrib/python/ipython/py3/IPython/core/extensions.py26
-rw-r--r--contrib/python/ipython/py3/IPython/core/oinspect.py39
-rw-r--r--contrib/python/ipython/py3/IPython/core/payload.py3
-rw-r--r--contrib/python/ipython/py3/IPython/core/profileapp.py2
-rw-r--r--contrib/python/ipython/py3/IPython/core/release.py2
-rw-r--r--contrib/python/ipython/py3/IPython/core/ultratb.py15
10 files changed, 190 insertions, 158 deletions
diff --git a/contrib/python/ipython/py3/IPython/core/alias.py b/contrib/python/ipython/py3/IPython/core/alias.py
index 2ad990231a..52843b3d77 100644
--- a/contrib/python/ipython/py3/IPython/core/alias.py
+++ b/contrib/python/ipython/py3/IPython/core/alias.py
@@ -190,22 +190,28 @@ class Alias(object):
#-----------------------------------------------------------------------------
class AliasManager(Configurable):
-
- default_aliases = List(default_aliases()).tag(config=True)
- user_aliases = List(default_value=[]).tag(config=True)
- shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
+ default_aliases: List = List(default_aliases()).tag(config=True)
+ user_aliases: List = List(default_value=[]).tag(config=True)
+ shell = Instance(
+ "IPython.core.interactiveshell.InteractiveShellABC", allow_none=True
+ )
def __init__(self, shell=None, **kwargs):
super(AliasManager, self).__init__(shell=shell, **kwargs)
# For convenient access
- self.linemagics = self.shell.magics_manager.magics['line']
- self.init_aliases()
+ if self.shell is not None:
+ self.linemagics = self.shell.magics_manager.magics["line"]
+ self.init_aliases()
def init_aliases(self):
# Load default & user aliases
for name, cmd in self.default_aliases + self.user_aliases:
- if cmd.startswith('ls ') and self.shell.colors == 'NoColor':
- cmd = cmd.replace(' --color', '')
+ if (
+ cmd.startswith("ls ")
+ and self.shell is not None
+ and self.shell.colors == "NoColor"
+ ):
+ cmd = cmd.replace(" --color", "")
self.soft_define_alias(name, cmd)
@property
@@ -246,7 +252,7 @@ class AliasManager(Configurable):
raise ValueError('%s is not an alias' % name)
def clear_aliases(self):
- for name, cmd in self.aliases:
+ for name, _ in self.aliases:
self.undefine_alias(name)
def retrieve_alias(self, name):
diff --git a/contrib/python/ipython/py3/IPython/core/application.py b/contrib/python/ipython/py3/IPython/core/application.py
index e0a8174f15..841e867a74 100644
--- a/contrib/python/ipython/py3/IPython/core/application.py
+++ b/contrib/python/ipython/py3/IPython/core/application.py
@@ -213,7 +213,9 @@ class BaseIPythonApplication(Application):
return d
_in_init_profile_dir = False
+
profile_dir = Instance(ProfileDir, allow_none=True)
+
@default('profile_dir')
def _profile_dir_default(self):
# avoid recursion
@@ -226,11 +228,13 @@ class BaseIPythonApplication(Application):
overwrite = Bool(False,
help="""Whether to overwrite existing config files when copying"""
).tag(config=True)
+
auto_create = Bool(False,
help="""Whether to create profile dir if it doesn't exist"""
).tag(config=True)
config_files = List(Unicode())
+
@default('config_files')
def _config_files_default(self):
return [self.config_file_name]
diff --git a/contrib/python/ipython/py3/IPython/core/debugger.py b/contrib/python/ipython/py3/IPython/core/debugger.py
index f370070140..b409416ece 100644
--- a/contrib/python/ipython/py3/IPython/core/debugger.py
+++ b/contrib/python/ipython/py3/IPython/core/debugger.py
@@ -1111,10 +1111,13 @@ class InterruptiblePdb(Pdb):
raise
-def set_trace(frame=None):
+def set_trace(frame=None, header=None):
"""
Start debugging from `frame`.
If frame is not specified, debugging starts from caller's frame.
"""
- Pdb().set_trace(frame or sys._getframe().f_back)
+ pdb = Pdb()
+ if header is not None:
+ pdb.message(header)
+ pdb.set_trace(frame or sys._getframe().f_back)
diff --git a/contrib/python/ipython/py3/IPython/core/excolors.py b/contrib/python/ipython/py3/IPython/core/excolors.py
index 85eef81f0e..5b7bcf6c09 100644
--- a/contrib/python/ipython/py3/IPython/core/excolors.py
+++ b/contrib/python/ipython/py3/IPython/core/excolors.py
@@ -42,118 +42,128 @@ def exception_colors():
ex_colors = ColorSchemeTable()
# Populate it with color schemes
- C = TermColors # shorthand and local lookup
- ex_colors.add_scheme(ColorScheme(
- 'NoColor',
- # The color to be used for the top line
- topline = C.NoColor,
-
- # The colors to be used in the traceback
- filename = C.NoColor,
- lineno = C.NoColor,
- name = C.NoColor,
- vName = C.NoColor,
- val = C.NoColor,
- em = C.NoColor,
-
- # Emphasized colors for the last frame of the traceback
- normalEm = C.NoColor,
- filenameEm = C.NoColor,
- linenoEm = C.NoColor,
- nameEm = C.NoColor,
- valEm = C.NoColor,
-
- # Colors for printing the exception
- excName = C.NoColor,
- line = C.NoColor,
- caret = C.NoColor,
- Normal = C.NoColor
- ))
+ C = TermColors # shorthand and local lookup
+ ex_colors.add_scheme(
+ ColorScheme(
+ "NoColor",
+ {
+ # The color to be used for the top line
+ "topline": C.NoColor,
+
+ # The colors to be used in the traceback
+ "filename": C.NoColor,
+ "lineno": C.NoColor,
+ "name": C.NoColor,
+ "vName": C.NoColor,
+ "val": C.NoColor,
+ "em": C.NoColor,
+
+ # Emphasized colors for the last frame of the traceback
+ "normalEm": C.NoColor,
+ "filenameEm": C.NoColor,
+ "linenoEm": C.NoColor,
+ "nameEm": C.NoColor,
+ "valEm": C.NoColor,
+
+ # Colors for printing the exception
+ "excName": C.NoColor,
+ "line": C.NoColor,
+ "caret": C.NoColor,
+ "Normal": C.NoColor,
+ },
+ )
+ )
# make some schemes as instances so we can copy them for modification easily
- ex_colors.add_scheme(ColorScheme(
- 'Linux',
- # The color to be used for the top line
- topline = C.LightRed,
-
- # The colors to be used in the traceback
- filename = C.Green,
- lineno = C.Green,
- name = C.Purple,
- vName = C.Cyan,
- val = C.Green,
- em = C.LightCyan,
-
- # Emphasized colors for the last frame of the traceback
- normalEm = C.LightCyan,
- filenameEm = C.LightGreen,
- linenoEm = C.LightGreen,
- nameEm = C.LightPurple,
- valEm = C.LightBlue,
-
- # Colors for printing the exception
- excName = C.LightRed,
- line = C.Yellow,
- caret = C.White,
- Normal = C.Normal
- ))
+ ex_colors.add_scheme(
+ ColorScheme(
+ "Linux",
+ {
+ # The color to be used for the top line
+ "topline": C.LightRed,
+ # The colors to be used in the traceback
+ "filename": C.Green,
+ "lineno": C.Green,
+ "name": C.Purple,
+ "vName": C.Cyan,
+ "val": C.Green,
+ "em": C.LightCyan,
+ # Emphasized colors for the last frame of the traceback
+ "normalEm": C.LightCyan,
+ "filenameEm": C.LightGreen,
+ "linenoEm": C.LightGreen,
+ "nameEm": C.LightPurple,
+ "valEm": C.LightBlue,
+ # Colors for printing the exception
+ "excName": C.LightRed,
+ "line": C.Yellow,
+ "caret": C.White,
+ "Normal": C.Normal,
+ },
+ )
+ )
# For light backgrounds, swap dark/light colors
- ex_colors.add_scheme(ColorScheme(
- 'LightBG',
- # The color to be used for the top line
- topline = C.Red,
-
- # The colors to be used in the traceback
- filename = C.LightGreen,
- lineno = C.LightGreen,
- name = C.LightPurple,
- vName = C.Cyan,
- val = C.LightGreen,
- em = C.Cyan,
-
- # Emphasized colors for the last frame of the traceback
- normalEm = C.Cyan,
- filenameEm = C.Green,
- linenoEm = C.Green,
- nameEm = C.Purple,
- valEm = C.Blue,
-
- # Colors for printing the exception
- excName = C.Red,
- #line = C.Brown, # brown often is displayed as yellow
- line = C.Red,
- caret = C.Normal,
- Normal = C.Normal,
- ))
-
- ex_colors.add_scheme(ColorScheme(
- 'Neutral',
- # The color to be used for the top line
- topline = C.Red,
-
- # The colors to be used in the traceback
- filename = C.LightGreen,
- lineno = C.LightGreen,
- name = C.LightPurple,
- vName = C.Cyan,
- val = C.LightGreen,
- em = C.Cyan,
-
- # Emphasized colors for the last frame of the traceback
- normalEm = C.Cyan,
- filenameEm = C.Green,
- linenoEm = C.Green,
- nameEm = C.Purple,
- valEm = C.Blue,
-
- # Colors for printing the exception
- excName = C.Red,
- #line = C.Brown, # brown often is displayed as yellow
- line = C.Red,
- caret = C.Normal,
- Normal = C.Normal,
- ))
+ ex_colors.add_scheme(
+ ColorScheme(
+ "LightBG",
+ {
+ # The color to be used for the top line
+ "topline": C.Red,
+
+ # The colors to be used in the traceback
+ "filename": C.LightGreen,
+ "lineno": C.LightGreen,
+ "name": C.LightPurple,
+ "vName": C.Cyan,
+ "val": C.LightGreen,
+ "em": C.Cyan,
+
+ # Emphasized colors for the last frame of the traceback
+ "normalEm": C.Cyan,
+ "filenameEm": C.Green,
+ "linenoEm": C.Green,
+ "nameEm": C.Purple,
+ "valEm": C.Blue,
+
+ # Colors for printing the exception
+ "excName": C.Red,
+ # "line": C.Brown, # brown often is displayed as yellow
+ "line": C.Red,
+ "caret": C.Normal,
+ "Normal": C.Normal,
+ },
+ )
+ )
+
+ ex_colors.add_scheme(
+ ColorScheme(
+ "Neutral",
+ {
+ # The color to be used for the top line
+ "topline": C.Red,
+ # The colors to be used in the traceback
+ "filename": C.LightGreen,
+ "lineno": C.LightGreen,
+ "name": C.LightPurple,
+ "vName": C.Cyan,
+ "val": C.LightGreen,
+ "em": C.Cyan,
+ # Emphasized colors for the last frame of the traceback
+ "normalEm": C.Cyan,
+ "filenameEm": C.Green,
+ "linenoEm": C.Green,
+ "nameEm": C.Purple,
+ "valEm": C.Blue,
+ # Colors for printing the exception
+ "excName": C.Red,
+ # line = C.Brown, # brown often is displayed as yellow
+ "line": C.Red,
+ "caret": C.Normal,
+ "Normal": C.Normal,
+ },
+ )
+ )
# Hack: the 'neutral' colours are not very visible on a dark background on
# Windows. Since Windows command prompts have a dark background by default, and
diff --git a/contrib/python/ipython/py3/IPython/core/extensions.py b/contrib/python/ipython/py3/IPython/core/extensions.py
index 21fba40eaf..27c6a4116d 100644
--- a/contrib/python/ipython/py3/IPython/core/extensions.py
+++ b/contrib/python/ipython/py3/IPython/core/extensions.py
@@ -10,8 +10,7 @@ import sys
from importlib import import_module, reload
from traitlets.config.configurable import Configurable
-from IPython.utils.path import ensure_dir_exists, compress_user
-from IPython.utils.decorators import undoc
+from IPython.utils.path import ensure_dir_exists
from traitlets import Instance
@@ -36,35 +35,22 @@ class ExtensionManager(Configurable):
the only argument. You can do anything you want with IPython at
that point, including defining new magic and aliases, adding new
components, etc.
-
+
You can also optionally define an :func:`unload_ipython_extension(ipython)`
function, which will be called if the user unloads or reloads the extension.
The extension manager will only call :func:`load_ipython_extension` again
if the extension is reloaded.
You can put your extension modules anywhere you want, as long as
- they can be imported by Python's standard import mechanism. However,
- to make it easy to write extensions, you can also put your extensions
- in ``os.path.join(self.ipython_dir, 'extensions')``. This directory
- is added to ``sys.path`` automatically.
+ they can be imported by Python's standard import mechanism.
"""
shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
def __init__(self, shell=None, **kwargs):
super(ExtensionManager, self).__init__(shell=shell, **kwargs)
- self.shell.observe(
- self._on_ipython_dir_changed, names=('ipython_dir',)
- )
self.loaded = set()
- @property
- def ipython_extension_dir(self):
- return os.path.join(self.shell.ipython_dir, u'extensions')
-
- def _on_ipython_dir_changed(self, change):
- ensure_dir_exists(self.ipython_extension_dir)
-
def load_extension(self, module_str: str):
"""Load an IPython extension by its module name.
@@ -84,7 +70,7 @@ class ExtensionManager(Configurable):
if module_str in self.loaded:
return "already loaded"
- from IPython.utils.syspathcontext import prepended_to_syspath
+ assert self.shell is not None
with self.shell.builtin_trap:
if module_str not in sys.modules:
@@ -125,7 +111,6 @@ class ExtensionManager(Configurable):
:func:`reload` is called and then the :func:`load_ipython_extension`
function of the module, if it exists is called.
"""
- from IPython.utils.syspathcontext import prepended_to_syspath
if BUILTINS_EXTS.get(module_str, False) is True:
module_str = "IPython.extensions." + module_str
@@ -133,8 +118,7 @@ class ExtensionManager(Configurable):
if (module_str in self.loaded) and (module_str in sys.modules):
self.unload_extension(module_str)
mod = sys.modules[module_str]
- with prepended_to_syspath(self.ipython_extension_dir):
- reload(mod)
+ reload(mod)
if self._call_load_ipython_extension(mod):
self.loaded.add(module_str)
else:
diff --git a/contrib/python/ipython/py3/IPython/core/oinspect.py b/contrib/python/ipython/py3/IPython/core/oinspect.py
index a8be281975..9eecf290ae 100644
--- a/contrib/python/ipython/py3/IPython/core/oinspect.py
+++ b/contrib/python/ipython/py3/IPython/core/oinspect.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
"""Tools for inspecting Python objects.
Uses syntax highlighting for presenting the various information elements.
@@ -22,7 +21,6 @@ import inspect
import io as stdlib_io
import linecache
import os
-import sys
import types
import warnings
@@ -30,6 +28,8 @@ from typing import Any, Optional, Dict, Union, List, Tuple
from typing import TypeAlias
+import traitlets
+
# IPython's own
from IPython.core import page
from IPython.lib.pretty import pretty
@@ -41,7 +41,7 @@ from IPython.utils.path import compress_user
from IPython.utils.text import indent
from IPython.utils.wildcard import list_namespace
from IPython.utils.wildcard import typestr2type
-from IPython.utils.coloransi import TermColors, ColorScheme, ColorSchemeTable
+from IPython.utils.coloransi import TermColors
from IPython.utils.py3compat import cast_unicode
from IPython.utils.colorable import Colorable
from IPython.utils.decorators import undoc
@@ -145,7 +145,7 @@ def get_encoding(obj):
# getsourcelines returns lineno with 1-offset and page() uses
# 0-offset, so we must adjust.
with stdlib_io.open(ofile, 'rb') as buffer: # Tweaked to use io.open for Python 2
- encoding, lines = openpy.detect_encoding(buffer.readline)
+ encoding, _lines = openpy.detect_encoding(buffer.readline)
return encoding
def getdoc(obj) -> Union[str,None]:
@@ -328,7 +328,7 @@ def _get_wrapped(obj):
return orig_obj
return obj
-def find_file(obj) -> str:
+def find_file(obj) -> Optional[str]:
"""Find the absolute path to the file where an object was defined.
This is essentially a robust wrapper around `inspect.getabsfile`.
@@ -346,7 +346,7 @@ def find_file(obj) -> str:
"""
obj = _get_wrapped(obj)
- fname = None
+ fname: Optional[str] = None
try:
fname = inspect.getabsfile(obj)
except TypeError:
@@ -360,7 +360,7 @@ def find_file(obj) -> str:
except OSError:
pass
- return cast_unicode(fname)
+ return fname
def find_source_lines(obj):
@@ -396,11 +396,20 @@ def find_source_lines(obj):
class Inspector(Colorable):
- def __init__(self, color_table=InspectColors,
- code_color_table=PyColorize.ANSICodeColors,
- scheme=None,
- str_detail_level=0,
- parent=None, config=None):
+ mime_hooks = traitlets.Dict(
+ config=True,
+ help="dictionary of mime to callable to add informations into help mimebundle dict",
+ ).tag(config=True)
+
+ def __init__(
+ self,
+ color_table=InspectColors,
+ code_color_table=PyColorize.ANSICodeColors,
+ scheme=None,
+ str_detail_level=0,
+ parent=None,
+ config=None,
+ ):
super(Inspector, self).__init__(parent=parent, config=config)
self.color_table = color_table
self.parser = PyColorize.Parser(out='str', parent=self, style=scheme)
@@ -625,7 +634,7 @@ class Inspector(Colorable):
if k in ("text/html", "text/plain"):
continue
else:
- new_b = bundle[k] # type:ignore
+ new_b[k] = bundle[k] # type:ignore
return new_b
def _append_info_field(
@@ -759,6 +768,10 @@ class Inspector(Colorable):
detail_level=detail_level,
omit_sections=omit_sections,
)
+ for key, hook in self.mime_hooks.items():
+ res = hook(obj, info)
+ if res is not None:
+ bundle[key] = res
return self.format_mime(bundle)
def pinfo(
diff --git a/contrib/python/ipython/py3/IPython/core/payload.py b/contrib/python/ipython/py3/IPython/core/payload.py
index 6818be1537..28eb7c80d3 100644
--- a/contrib/python/ipython/py3/IPython/core/payload.py
+++ b/contrib/python/ipython/py3/IPython/core/payload.py
@@ -26,8 +26,7 @@ from traitlets import List
#-----------------------------------------------------------------------------
class PayloadManager(Configurable):
-
- _payload = List([])
+ _payload: List = List([])
def write_payload(self, data, single=True):
"""Include or update the specified `data` payload in the PayloadManager.
diff --git a/contrib/python/ipython/py3/IPython/core/profileapp.py b/contrib/python/ipython/py3/IPython/core/profileapp.py
index 9a1bae55ac..94cc0352e8 100644
--- a/contrib/python/ipython/py3/IPython/core/profileapp.py
+++ b/contrib/python/ipython/py3/IPython/core/profileapp.py
@@ -209,7 +209,7 @@ class ProfileCreate(BaseIPythonApplication):
name = u'ipython-profile'
description = create_help
examples = _create_examples
- auto_create = Bool(True)
+ auto_create = Bool(True).tag(config=True)
def _log_format_default(self):
return "[%(name)s] %(message)s"
diff --git a/contrib/python/ipython/py3/IPython/core/release.py b/contrib/python/ipython/py3/IPython/core/release.py
index ec50c45721..f71ee85c08 100644
--- a/contrib/python/ipython/py3/IPython/core/release.py
+++ b/contrib/python/ipython/py3/IPython/core/release.py
@@ -16,7 +16,7 @@
# release. 'dev' as a _version_extra string means this is a development
# version
_version_major = 8
-_version_minor = 20
+_version_minor = 21
_version_patch = 0
_version_extra = ".dev"
# _version_extra = "rc1"
diff --git a/contrib/python/ipython/py3/IPython/core/ultratb.py b/contrib/python/ipython/py3/IPython/core/ultratb.py
index cb0d8f951f..b0f9e08a3d 100644
--- a/contrib/python/ipython/py3/IPython/core/ultratb.py
+++ b/contrib/python/ipython/py3/IPython/core/ultratb.py
@@ -789,7 +789,20 @@ class FrameInfo:
@property
def lines(self):
- return self._sd.lines
+ from executing.executing import NotOneValueFound
+
+ try:
+ return self._sd.lines
+ except NotOneValueFound:
+
+ class Dummy:
+ lineno = 0
+ is_current = False
+
+ def render(self, *, pygmented):
+ return "<Error retrieving source code with stack_data see ipython/ipython#13598>"
+
+ return [Dummy()]
@property
def executing(self):