diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-06-15 14:18:22 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-06-15 14:27:16 +0300 |
commit | b52a8ab5cd66952839ada0843539b5564108a052 (patch) | |
tree | 659c3387aee1dbb2629b3afd68f8d306d37b45c2 /contrib/python/ipython/py3/IPython/core | |
parent | 7d673060f61f85b3e440fa45df26795d3653c8d2 (diff) | |
download | ydb-b52a8ab5cd66952839ada0843539b5564108a052.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib/python/ipython/py3/IPython/core')
18 files changed, 92 insertions, 54 deletions
diff --git a/contrib/python/ipython/py3/IPython/core/completerlib.py b/contrib/python/ipython/py3/IPython/core/completerlib.py index de6c4249b0..05f39e5015 100644 --- a/contrib/python/ipython/py3/IPython/core/completerlib.py +++ b/contrib/python/ipython/py3/IPython/core/completerlib.py @@ -199,9 +199,14 @@ def get_root_modules(): return rootmodules -def is_importable(module, attr, only_modules): +def is_importable(module, attr: str, only_modules) -> bool: if only_modules: - return inspect.ismodule(getattr(module, attr)) + try: + mod = getattr(module, attr) + except ModuleNotFoundError: + # See gh-14434 + return False + return inspect.ismodule(mod) else: return not(attr[:2] == '__' and attr[-2:] == '__') diff --git a/contrib/python/ipython/py3/IPython/core/historyapp.py b/contrib/python/ipython/py3/IPython/core/historyapp.py index 85dd9c5c3b..d555447b5d 100644 --- a/contrib/python/ipython/py3/IPython/core/historyapp.py +++ b/contrib/python/ipython/py3/IPython/core/historyapp.py @@ -146,9 +146,11 @@ class HistoryApp(Application): def start(self): if self.subapp is None: - print("No subcommand specified. Must specify one of: %s" % \ - (self.subcommands.keys())) - print() + print( + "No subcommand specified. Must specify one of: " + + ", ".join(map(repr, self.subcommands)) + + ".\n" + ) self.print_description() self.print_subcommands() self.exit(1) diff --git a/contrib/python/ipython/py3/IPython/core/hooks.py b/contrib/python/ipython/py3/IPython/core/hooks.py index f73c565763..484ebe459a 100644 --- a/contrib/python/ipython/py3/IPython/core/hooks.py +++ b/contrib/python/ipython/py3/IPython/core/hooks.py @@ -19,7 +19,7 @@ example, you could use a startup file like this:: def calljed(self,filename, linenum): "My editor hook calls the jed editor directly." - print "Calling my own editor, jed ..." + print("Calling my own editor, jed ...") if os.system('jed +%d %s' % (linenum,filename)) != 0: raise TryNext() @@ -111,7 +111,7 @@ class CommandChainDispatcher: TryNext""" last_exc = TryNext() for prio,cmd in self.chain: - #print "prio",prio,"cmd",cmd #dbg + # print("prio",prio,"cmd",cmd) # dbg try: return cmd(*args, **kw) except TryNext as exc: diff --git a/contrib/python/ipython/py3/IPython/core/inputsplitter.py b/contrib/python/ipython/py3/IPython/core/inputsplitter.py index f1ebd96b69..af7a12e6e0 100644 --- a/contrib/python/ipython/py3/IPython/core/inputsplitter.py +++ b/contrib/python/ipython/py3/IPython/core/inputsplitter.py @@ -320,7 +320,7 @@ class InputSplitter(object): prompt = '>>> ' + indent line = indent + raw_input(prompt) isp.push(line) - print 'Input source was:\n', isp.source_reset(), + print('Input source was:\n', isp.source_reset()) """ # A cache for storing the current indentation # The first value stores the most recently processed source input diff --git a/contrib/python/ipython/py3/IPython/core/interactiveshell.py b/contrib/python/ipython/py3/IPython/core/interactiveshell.py index e9e649345f..86eb7191e8 100644 --- a/contrib/python/ipython/py3/IPython/core/interactiveshell.py +++ b/contrib/python/ipython/py3/IPython/core/interactiveshell.py @@ -909,7 +909,7 @@ class InteractiveShell(SingletonConfigurable): paths = self.get_path_links(p) # In Cygwin paths like "c:\..." and '\cygdrive\c\...' are possible - if p_venv.parts[1] == "cygdrive": + if len(p_venv.parts) > 2 and p_venv.parts[1] == "cygdrive": drive_name = p_venv.parts[2] p_venv = (drive_name + ":/") / Path(*p_venv.parts[3:]) diff --git a/contrib/python/ipython/py3/IPython/core/logger.py b/contrib/python/ipython/py3/IPython/core/logger.py index ab12d10e22..101665bcc2 100644 --- a/contrib/python/ipython/py3/IPython/core/logger.py +++ b/contrib/python/ipython/py3/IPython/core/logger.py @@ -191,7 +191,7 @@ which already exists. But you must first start the logging process with def log_write(self, data, kind='input'): """Write data to the log file, if active""" - #print 'data: %r' % data # dbg + # print('data: %r' % data) # dbg if self.log_active and data: write = self.logfile.write if kind=='input': diff --git a/contrib/python/ipython/py3/IPython/core/magics/code.py b/contrib/python/ipython/py3/IPython/core/magics/code.py index 65ba52b8bb..4f1574dcef 100644 --- a/contrib/python/ipython/py3/IPython/core/magics/code.py +++ b/contrib/python/ipython/py3/IPython/core/magics/code.py @@ -452,7 +452,7 @@ class CodeMagics(Magics): # Load the parameter given as a variable. If not a string, # process it as an object instead (below) - #print '*** args',args,'type',type(args) # dbg + # print('*** args',args,'type',type(args)) # dbg data = eval(args, shell.user_ns) if not isinstance(data, str): raise DataIsObject @@ -636,8 +636,8 @@ class CodeMagics(Magics): In [1]: edit Editing... done. Executing edited code... - Out[1]: 'def foo():\\n print "foo() was defined in an editing - session"\\n' + Out[1]: 'def foo():\\n print("foo() was defined in an editing + session")\\n' We can then call the function foo():: @@ -661,21 +661,21 @@ class CodeMagics(Magics): In [5]: edit Editing... done. Executing edited code... hello - Out[5]: "print 'hello'\\n" + Out[5]: "print('hello')\\n" Now we call it again with the previous output (stored in _):: In [6]: edit _ Editing... done. Executing edited code... hello world - Out[6]: "print 'hello world'\\n" + Out[6]: "print('hello world')\\n" Now we call it with the output #8 (stored in _8, also as Out[8]):: In [7]: edit _8 Editing... done. Executing edited code... hello again - Out[7]: "print 'hello again'\\n" + Out[7]: "print('hello again')\\n" Changing the default editor hook: diff --git a/contrib/python/ipython/py3/IPython/core/magics/execution.py b/contrib/python/ipython/py3/IPython/core/magics/execution.py index f3688f4eb0..abfc4cbda7 100644 --- a/contrib/python/ipython/py3/IPython/core/magics/execution.py +++ b/contrib/python/ipython/py3/IPython/core/magics/execution.py @@ -1256,7 +1256,7 @@ class ExecutionMagics(Magics): Wall time: 1.37 Out[3]: 499999500000L - In [4]: %time print 'hello world' + In [4]: %time print('hello world') hello world CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s Wall time: 0.00 @@ -1406,9 +1406,9 @@ class ExecutionMagics(Magics): 44: x=1 45: y=3 46: z=x+y - 47: print x + 47: print(x) 48: a=5 - 49: print 'x',x,'y',y + 49: print('x',x,'y',y) you can create a macro with lines 44 through 47 (included) and line 49 called my_macro with:: @@ -1428,7 +1428,7 @@ class ExecutionMagics(Magics): You can view a macro's contents by explicitly printing it with:: - print macro_name + print(macro_name) """ opts,args = self.parse_options(parameter_s,'rq',mode='list') @@ -1439,7 +1439,7 @@ class ExecutionMagics(Magics): "%macro insufficient args; usage '%macro name n1-n2 n3-4...") name, codefrom = args[0], " ".join(args[1:]) - #print 'rng',ranges # dbg + # print('rng',ranges) # dbg try: lines = self.shell.find_user_code(codefrom, 'r' in opts) except (ValueError, TypeError) as e: @@ -1592,17 +1592,17 @@ def _format_time(timespan, precision=3): break return " ".join(time) - - # Unfortunately the unicode 'micro' symbol can cause problems in - # certain terminals. + + # Unfortunately characters outside of range(128) can cause problems in + # certain terminals. # See bug: https://bugs.launchpad.net/ipython/+bug/348466 # Try to prevent crashes by being more secure than it needs to # E.g. eclipse is able to print a µ, but has no sys.stdout.encoding set. - units = [u"s", u"ms",u'us',"ns"] # the save value - if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding: + units = ["s", "ms", "us", "ns"] # the safe value + if hasattr(sys.stdout, "encoding") and sys.stdout.encoding: try: - u'\xb5'.encode(sys.stdout.encoding) - units = [u"s", u"ms",u'\xb5s',"ns"] + "μ".encode(sys.stdout.encoding) + units = ["s", "ms", "μs", "ns"] except: pass scaling = [1, 1e3, 1e6, 1e9] diff --git a/contrib/python/ipython/py3/IPython/core/magics/history.py b/contrib/python/ipython/py3/IPython/core/magics/history.py index faa4335faa..8343677451 100644 --- a/contrib/python/ipython/py3/IPython/core/magics/history.py +++ b/contrib/python/ipython/py3/IPython/core/magics/history.py @@ -128,7 +128,7 @@ class HistoryMagics(Magics): In [6]: %history -n 4-6 4:a = 12 - 5:print a**2 + 5:print(a**2) 6:%history -n 4-6 """ diff --git a/contrib/python/ipython/py3/IPython/core/magics/namespace.py b/contrib/python/ipython/py3/IPython/core/magics/namespace.py index 5da8f7161a..737a76507f 100644 --- a/contrib/python/ipython/py3/IPython/core/magics/namespace.py +++ b/contrib/python/ipython/py3/IPython/core/magics/namespace.py @@ -43,7 +43,7 @@ class NamespaceMagics(Magics): '%pinfo object' is just a synonym for object? or ?object.""" - #print 'pinfo par: <%s>' % parameter_s # dbg + # print('pinfo par: <%s>' % parameter_s) # dbg # detail_level: 0 -> obj? , 1 -> obj?? detail_level = 0 # We need to detect if we got called as 'pinfo pinfo foo', which can diff --git a/contrib/python/ipython/py3/IPython/core/oinspect.py b/contrib/python/ipython/py3/IPython/core/oinspect.py index 937e5a9d4b..8aa8429e5d 100644 --- a/contrib/python/ipython/py3/IPython/core/oinspect.py +++ b/contrib/python/ipython/py3/IPython/core/oinspect.py @@ -1196,7 +1196,7 @@ class Inspector(Colorable): - list_types(False): list all available object types for object matching. """ - #print 'ps pattern:<%r>' % pattern # dbg + # print('ps pattern:<%r>' % pattern) # dbg # defaults type_pattern = 'all' @@ -1225,7 +1225,7 @@ class Inspector(Colorable): raise ValueError('invalid namespace <%s>. Valid names: %s' % (name,ns_table.keys())) - #print 'type_pattern:',type_pattern # dbg + # print('type_pattern:',type_pattern) # dbg search_result, namespaces_seen = set(), set() for ns_name in ns_search: ns = ns_table[ns_name] diff --git a/contrib/python/ipython/py3/IPython/core/page.py b/contrib/python/ipython/py3/IPython/core/page.py index d3e6a9eef5..31b314ec46 100644 --- a/contrib/python/ipython/py3/IPython/core/page.py +++ b/contrib/python/ipython/py3/IPython/core/page.py @@ -122,8 +122,8 @@ def _detect_screen_size(screen_lines_def): termios.tcsetattr(sys.stdout,termios.TCSANOW,term_flags) # Now we have what we needed: the screen size in rows/columns return screen_lines_real - #print '***Screen size:',screen_lines_real,'lines x',\ - #screen_cols,'columns.' # dbg + # print('***Screen size:',screen_lines_real,'lines x', + # screen_cols,'columns.') # dbg def pager_page(strng, start=0, screen_lines=0, pager_cmd=None): """Display a string, piping through a pager after a certain length. @@ -179,9 +179,9 @@ def pager_page(strng, start=0, screen_lines=0, pager_cmd=None): print(str_toprint) return - #print 'numlines',numlines,'screenlines',screen_lines # dbg + # print('numlines',numlines,'screenlines',screen_lines) # dbg if numlines <= screen_lines : - #print '*** normal print' # dbg + # print('*** normal print') # dbg print(str_toprint) else: # Try to open pager and default to internal one if that fails. diff --git a/contrib/python/ipython/py3/IPython/core/prefilter.py b/contrib/python/ipython/py3/IPython/core/prefilter.py index 5b1b86c753..e611b4b834 100644 --- a/contrib/python/ipython/py3/IPython/core/prefilter.py +++ b/contrib/python/ipython/py3/IPython/core/prefilter.py @@ -240,7 +240,7 @@ class PrefilterManager(Configurable): This implements the checker/handler part of the prefilter pipe. """ - # print "prefilter_line_info: ", line_info + # print("prefilter_line_info: ", line_info) handler = self.find_handler(line_info) return handler.handle(line_info) @@ -267,7 +267,7 @@ class PrefilterManager(Configurable): transformers and then the checkers/handlers. """ - # print "prefilter_line: ", line, continue_prompt + # print("prefilter_line: ", line, continue_prompt) # All handlers *must* return a value, even if it's blank (''). # save the line away in case we crash, so the post-mortem handler can @@ -300,7 +300,7 @@ class PrefilterManager(Configurable): return normal_handler.handle(line_info) prefiltered = self.prefilter_line_info(line_info) - # print "prefiltered line: %r" % prefiltered + # print("prefiltered line: %r" % prefiltered) return prefiltered def prefilter_lines(self, lines, continue_prompt=False): @@ -544,7 +544,7 @@ class PrefilterHandler(Configurable): ) def handle(self, line_info): - # print "normal: ", line_info + # print("normal: ", line_info) """Handle normal input lines. Use as a template for handlers.""" # With autoindent on, we need some way to exit the input loop, and I diff --git a/contrib/python/ipython/py3/IPython/core/profileapp.py b/contrib/python/ipython/py3/IPython/core/profileapp.py index 94cc0352e8..e7538ff201 100644 --- a/contrib/python/ipython/py3/IPython/core/profileapp.py +++ b/contrib/python/ipython/py3/IPython/core/profileapp.py @@ -303,8 +303,11 @@ class ProfileApp(Application): def start(self): if self.subapp is None: - print("No subcommand specified. Must specify one of: %s"%(self.subcommands.keys())) - print() + print( + "No subcommand specified. Must specify one of: " + + ", ".join(map(repr, self.subcommands)) + + ".\n" + ) self.print_description() self.print_subcommands() self.exit(1) diff --git a/contrib/python/ipython/py3/IPython/core/pylabtools.py b/contrib/python/ipython/py3/IPython/core/pylabtools.py index 1f5a11f37e..5c926a9c10 100644 --- a/contrib/python/ipython/py3/IPython/core/pylabtools.py +++ b/contrib/python/ipython/py3/IPython/core/pylabtools.py @@ -14,7 +14,7 @@ from IPython.utils.decorators import flag_calls # Matplotlib backend resolution functionality moved from IPython to Matplotlib -# in IPython 8.24 and Matplotlib 3.9.1. Need to keep `backends` and `backend2gui` +# in IPython 8.24 and Matplotlib 3.9.0. Need to keep `backends` and `backend2gui` # here for earlier Matplotlib and for external backend libraries such as # mplcairo that might rely upon it. _deprecated_backends = { @@ -224,7 +224,7 @@ def mpl_runner(safe_execfile): import matplotlib import matplotlib.pyplot as plt - #print '*** Matplotlib runner ***' # dbg + # print('*** Matplotlib runner ***') # dbg # turn off rendering until end of script with matplotlib.rc_context({"interactive": False}): safe_execfile(fname, *where, **kw) @@ -345,8 +345,10 @@ def find_gui_and_backend(gui=None, gui_select=None): backend = matplotlib.rcParamsOrig["backend"] backend, gui = backend_registry.resolve_backend(backend) else: + gui = _convert_gui_to_matplotlib(gui) backend, gui = backend_registry.resolve_gui_or_backend(gui) + gui = _convert_gui_from_matplotlib(gui) return gui, backend # Fallback to previous behaviour (Matplotlib < 3.9) @@ -485,6 +487,10 @@ def _matplotlib_manages_backends() -> bool: matplotlib.backends.registry.backend_registry is available along with member functions resolve_gui_or_backend, resolve_backend, list_all, and list_gui_frameworks. + + This function can be removed as it will always return True when Python + 3.12, the latest version supported by Matplotlib < 3.9, reaches + end-of-life in late 2028. """ global _matplotlib_manages_backends_value if _matplotlib_manages_backends_value is None: @@ -509,10 +515,28 @@ def _list_matplotlib_backends_and_gui_loops() -> list[str]: if _matplotlib_manages_backends(): from matplotlib.backends.registry import backend_registry - ret = backend_registry.list_all() + backend_registry.list_gui_frameworks() + ret = backend_registry.list_all() + [ + _convert_gui_from_matplotlib(gui) + for gui in backend_registry.list_gui_frameworks() + ] else: from IPython.core import pylabtools ret = list(pylabtools.backends.keys()) return sorted(["auto"] + ret) + + +# Matplotlib and IPython do not always use the same gui framework name. +# Always use the approprate one of these conversion functions when passing a +# gui framework name to/from Matplotlib. +def _convert_gui_to_matplotlib(gui: str | None) -> str | None: + if gui and gui.lower() == "osx": + return "macosx" + return gui + + +def _convert_gui_from_matplotlib(gui: str | None) -> str | None: + if gui and gui.lower() == "macosx": + return "osx" + return gui diff --git a/contrib/python/ipython/py3/IPython/core/release.py b/contrib/python/ipython/py3/IPython/core/release.py index 3abbedef73..431ce99874 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 = 24 +_version_minor = 25 _version_patch = 0 _version_extra = ".dev" # _version_extra = "rc1" diff --git a/contrib/python/ipython/py3/IPython/core/shellapp.py b/contrib/python/ipython/py3/IPython/core/shellapp.py index 99d1d8a9f4..3815a0ecb9 100644 --- a/contrib/python/ipython/py3/IPython/core/shellapp.py +++ b/contrib/python/ipython/py3/IPython/core/shellapp.py @@ -82,12 +82,14 @@ shell_flags['nosep']=(nosep_config, "Eliminate all spacing between prompts.") shell_flags['pylab'] = ( {'InteractiveShellApp' : {'pylab' : 'auto'}}, """Pre-load matplotlib and numpy for interactive use with - the default matplotlib backend.""" + the default matplotlib backend. The exact options available + depend on what Matplotlib provides at runtime.""", ) shell_flags['matplotlib'] = ( {'InteractiveShellApp' : {'matplotlib' : 'auto'}}, """Configure matplotlib for interactive use with - the default matplotlib backend.""" + the default matplotlib backend. The exact options available + depend on what Matplotlib provides at runtime.""", ) # it's possible we don't want short aliases for *all* of these: @@ -114,7 +116,7 @@ shell_aliases['cache-size'] = 'InteractiveShell.cache_size' class MatplotlibBackendCaselessStrEnum(CaselessStrEnum): """An enum of Matplotlib backend strings where the case should be ignored. - Prior to Matplotlib 3.9.1 the list of valid backends is hardcoded in + Prior to Matplotlib 3.9.0 the list of valid backends is hardcoded in pylabtools.backends. After that, Matplotlib manages backends. The list of valid backends is determined when it is first needed to avoid @@ -205,12 +207,14 @@ class InteractiveShellApp(Configurable): matplotlib = MatplotlibBackendCaselessStrEnum( allow_none=True, help="""Configure matplotlib for interactive use with - the default matplotlib backend.""", + the default matplotlib backend. The exact options available + depend on what Matplotlib provides at runtime.""", ).tag(config=True) pylab = MatplotlibBackendCaselessStrEnum( allow_none=True, help="""Pre-load matplotlib and numpy for interactive use, selecting a particular matplotlib backend and loop integration. + The exact options available depend on what Matplotlib provides at runtime. """, ).tag(config=True) pylab_import_all = Bool( diff --git a/contrib/python/ipython/py3/IPython/core/splitinput.py b/contrib/python/ipython/py3/IPython/core/splitinput.py index 5bc3e32542..0cd70ec910 100644 --- a/contrib/python/ipython/py3/IPython/core/splitinput.py +++ b/contrib/python/ipython/py3/IPython/core/splitinput.py @@ -63,19 +63,19 @@ def split_user_input(line, pattern=None): pattern = line_split match = pattern.match(line) if not match: - # print "match failed for line '%s'" % line + # print("match failed for line '%s'" % line) try: ifun, the_rest = line.split(None,1) except ValueError: - # print "split failed for line '%s'" % line + # print("split failed for line '%s'" % line) ifun, the_rest = line, u'' pre = re.match(r'^(\s*)(.*)',line).groups()[0] esc = "" else: pre, esc, ifun, the_rest = match.groups() - #print 'line:<%s>' % line # dbg - #print 'pre <%s> ifun <%s> rest <%s>' % (pre,ifun.strip(),the_rest) # dbg + # print('line:<%s>' % line) # dbg + # print('pre <%s> ifun <%s> rest <%s>' % (pre,ifun.strip(),the_rest)) # dbg return pre, esc or '', ifun.strip(), the_rest.lstrip() |