diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2023-11-14 19:18:07 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2023-11-14 20:20:53 +0300 |
commit | 874ef51d3d3edfa25f5a505ec6ab50e172965d1e (patch) | |
tree | 620fb5e02063d23509d3aa3df2215c099ccde0b7 /contrib/python/ipython/py3/IPython/utils | |
parent | e356b34d3b0399e2f170881af15c91e4db9e3d11 (diff) | |
download | ydb-874ef51d3d3edfa25f5a505ec6ab50e172965d1e.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib/python/ipython/py3/IPython/utils')
6 files changed, 86 insertions, 32 deletions
diff --git a/contrib/python/ipython/py3/IPython/utils/_sysinfo.py b/contrib/python/ipython/py3/IPython/utils/_sysinfo.py index 5e2eeadcf3..8d771a843f 100644 --- a/contrib/python/ipython/py3/IPython/utils/_sysinfo.py +++ b/contrib/python/ipython/py3/IPython/utils/_sysinfo.py @@ -1,2 +1,2 @@ # GENERATED BY setup.py -commit = "a2af83ddf" +commit = "0cfced36e" diff --git a/contrib/python/ipython/py3/IPython/utils/py3compat.py b/contrib/python/ipython/py3/IPython/utils/py3compat.py index 34af4c58f4..66ef337248 100644 --- a/contrib/python/ipython/py3/IPython/utils/py3compat.py +++ b/contrib/python/ipython/py3/IPython/utils/py3compat.py @@ -57,6 +57,7 @@ def execfile(fname, glob, loc=None, compiler=None): PYPY = platform.python_implementation() == "PyPy" + # Cython still rely on that as a Dec 28 2019 # See https://github.com/cython/cython/pull/3291 and # https://github.com/ipython/ipython/issues/12068 diff --git a/contrib/python/ipython/py3/IPython/utils/sysinfo.py b/contrib/python/ipython/py3/IPython/utils/sysinfo.py index 857f0cf2d8..347123fd53 100644 --- a/contrib/python/ipython/py3/IPython/utils/sysinfo.py +++ b/contrib/python/ipython/py3/IPython/utils/sysinfo.py @@ -20,6 +20,8 @@ import pprint import sys import subprocess +from pathlib import Path + from IPython.core import release from IPython.utils import _sysinfo, encoding @@ -27,7 +29,7 @@ from IPython.utils import _sysinfo, encoding # Code #----------------------------------------------------------------------------- -def pkg_commit_hash(pkg_path): +def pkg_commit_hash(pkg_path: str) -> tuple[str, str]: """Get short form of commit hash given directory `pkg_path` We get the commit hash from (in order of preference): @@ -65,7 +67,7 @@ def pkg_commit_hash(pkg_path): return '(none found)', '<not found>' -def pkg_info(pkg_path): +def pkg_info(pkg_path: str) -> dict: """Return dict describing the context of this package Parameters @@ -92,11 +94,10 @@ def pkg_info(pkg_path): default_encoding=encoding.DEFAULT_ENCODING, ) -def get_sys_info(): +def get_sys_info() -> dict: """Return useful information about IPython and the system, as a dict.""" - p = os.path - path = p.realpath(p.dirname(p.abspath(p.join(__file__, '..')))) - return pkg_info(path) + path = Path(__file__, "..").resolve().parent + return pkg_info(str(path)) def sys_info(): """Return useful information about IPython and the system, as a string. diff --git a/contrib/python/ipython/py3/IPython/utils/text.py b/contrib/python/ipython/py3/IPython/utils/text.py index 74bccddf68..9b653dcee0 100644 --- a/contrib/python/ipython/py3/IPython/utils/text.py +++ b/contrib/python/ipython/py3/IPython/utils/text.py @@ -13,15 +13,12 @@ import re import string import sys import textwrap +import warnings from string import Formatter from pathlib import Path +from typing import List, Union, Optional, Dict, Tuple -# datetime.strftime date format for ipython -if sys.platform == 'win32': - date_format = "%B %d, %Y" -else: - date_format = "%B %-d, %Y" class LSString(str): """String derivative with a special access attributes. @@ -336,7 +333,13 @@ ini_spaces_re = re.compile(r'^(\s+)') def num_ini_spaces(strng): """Return the number of initial spaces in a string""" - + warnings.warn( + "`num_ini_spaces` is Pending Deprecation since IPython 8.17." + "It is considered fro removal in in future version. " + "Please open an issue if you believe it should be kept.", + stacklevel=2, + category=PendingDeprecationWarning, + ) ini_spaces = ini_spaces_re.match(strng) if ini_spaces: return ini_spaces.end() @@ -391,6 +394,13 @@ def wrap_paragraphs(text, ncols=80): ------- list of complete paragraphs, wrapped to fill `ncols` columns. """ + warnings.warn( + "`wrap_paragraphs` is Pending Deprecation since IPython 8.17." + "It is considered fro removal in in future version. " + "Please open an issue if you believe it should be kept.", + stacklevel=2, + category=PendingDeprecationWarning, + ) paragraph_re = re.compile(r'\n(\s*\n)+', re.MULTILINE) text = dedent(text).strip() paragraphs = paragraph_re.split(text)[::2] # every other entry is space @@ -465,6 +475,14 @@ def strip_ansi(source): source : str Source to remove the ansi from """ + warnings.warn( + "`strip_ansi` is Pending Deprecation since IPython 8.17." + "It is considered fro removal in in future version. " + "Please open an issue if you believe it should be kept.", + stacklevel=2, + category=PendingDeprecationWarning, + ) + return re.sub(r'\033\[(\d|;)+?m', '', source) @@ -611,7 +629,7 @@ def _col_chunks(l, max_rows, row_first=False): yield l[i:(i + max_rows)] -def _find_optimal(rlist, row_first=False, separator_size=2, displaywidth=80): +def _find_optimal(rlist, row_first: bool, separator_size: int, displaywidth: int): """Calculate optimal info to columnize a list of string""" for max_rows in range(1, len(rlist) + 1): col_widths = list(map(max, _col_chunks(rlist, max_rows, row_first))) @@ -634,7 +652,9 @@ def _get_or_default(mylist, i, default=None): return mylist[i] -def compute_item_matrix(items, row_first=False, empty=None, *args, **kwargs) : +def compute_item_matrix( + items, row_first: bool = False, empty=None, *, separator_size=2, displaywidth=80 +) -> Tuple[List[List[int]], Dict[str, int]]: """Returns a nested list, and info to columnize items Parameters @@ -682,8 +702,20 @@ def compute_item_matrix(items, row_first=False, empty=None, *args, **kwargs) : In [5]: all((info[k] == ideal[k] for k in ideal.keys())) Out[5]: True """ - info = _find_optimal(list(map(len, items)), row_first, *args, **kwargs) - nrow, ncol = info['max_rows'], info['num_columns'] + warnings.warn( + "`compute_item_matrix` is Pending Deprecation since IPython 8.17." + "It is considered fro removal in in future version. " + "Please open an issue if you believe it should be kept.", + stacklevel=2, + category=PendingDeprecationWarning, + ) + info = _find_optimal( + list(map(len, items)), + row_first, + separator_size=separator_size, + displaywidth=displaywidth, + ) + nrow, ncol = info["max_rows"], info["num_columns"] if row_first: return ([[_get_or_default(items, r * ncol + c, default=empty) for c in range(ncol)] for r in range(nrow)], info) else: @@ -709,14 +741,29 @@ def columnize(items, row_first=False, separator=" ", displaywidth=80, spread=Fa ------- The formatted string. """ + warnings.warn( + "`columnize` is Pending Deprecation since IPython 8.17." + "It is considered fro removal in in future version. " + "Please open an issue if you believe it should be kept.", + stacklevel=2, + category=PendingDeprecationWarning, + ) if not items: - return '\n' - matrix, info = compute_item_matrix(items, row_first=row_first, separator_size=len(separator), displaywidth=displaywidth) + return "\n" + matrix: List[List[int]] + matrix, info = compute_item_matrix( + items, + row_first=row_first, + separator_size=len(separator), + displaywidth=displaywidth, + ) if spread: - separator = separator.ljust(int(info['optimal_separator_width'])) - fmatrix = [filter(None, x) for x in matrix] - sjoin = lambda x : separator.join([ y.ljust(w, ' ') for y, w in zip(x, info['column_widths'])]) - return '\n'.join(map(sjoin, fmatrix))+'\n' + separator = separator.ljust(int(info["optimal_separator_width"])) + fmatrix: List[filter[int]] = [filter(None, x) for x in matrix] + sjoin = lambda x: separator.join( + [y.ljust(w, " ") for y, w in zip(x, info["column_widths"])] + ) + return "\n".join(map(sjoin, fmatrix)) + "\n" def get_text_list(list_, last_sep=' and ', sep=", ", wrap_item_with=""): diff --git a/contrib/python/ipython/py3/IPython/utils/timing.py b/contrib/python/ipython/py3/IPython/utils/timing.py index 3a181ae728..d87e5fa8ef 100644 --- a/contrib/python/ipython/py3/IPython/utils/timing.py +++ b/contrib/python/ipython/py3/IPython/utils/timing.py @@ -23,8 +23,8 @@ import time # If possible (Unix), use the resource module instead of time.clock() try: import resource -except ImportError: - resource = None +except ModuleNotFoundError: + resource = None # type: ignore [assignment] # Some implementations (like jyputerlite) don't have getrusage if resource is not None and hasattr(resource, "getrusage"): diff --git a/contrib/python/ipython/py3/IPython/utils/tokenutil.py b/contrib/python/ipython/py3/IPython/utils/tokenutil.py index 5fd8a1fbe1..6b99a58ae2 100644 --- a/contrib/python/ipython/py3/IPython/utils/tokenutil.py +++ b/contrib/python/ipython/py3/IPython/utils/tokenutil.py @@ -8,12 +8,14 @@ from io import StringIO from keyword import iskeyword import tokenize +from tokenize import TokenInfo +from typing import List, Optional Token = namedtuple('Token', ['token', 'text', 'start', 'end', 'line']) def generate_tokens(readline): - """wrap generate_tokens to catch EOF errors""" + """wrap generate_tkens to catch EOF errors""" try: for token in tokenize.generate_tokens(readline): yield token @@ -22,7 +24,9 @@ def generate_tokens(readline): return -def generate_tokens_catch_errors(readline, extra_errors_to_catch=None): +def generate_tokens_catch_errors( + readline, extra_errors_to_catch: Optional[List[str]] = None +): default_errors_to_catch = [ "unterminated string literal", "invalid non-printable character", @@ -31,7 +35,7 @@ def generate_tokens_catch_errors(readline, extra_errors_to_catch=None): assert extra_errors_to_catch is None or isinstance(extra_errors_to_catch, list) errors_to_catch = default_errors_to_catch + (extra_errors_to_catch or []) - tokens = [] + tokens: List[TokenInfo] = [] try: for token in tokenize.generate_tokens(readline): tokens.append(token) @@ -84,7 +88,8 @@ def line_at_cursor(cell, cursor_pos=0): line = "" return (line, offset) -def token_at_cursor(cell, cursor_pos=0): + +def token_at_cursor(cell: str, cursor_pos: int = 0): """Get the token at a given cursor Used for introspection. @@ -94,13 +99,13 @@ def token_at_cursor(cell, cursor_pos=0): Parameters ---------- - cell : unicode + cell : str A block of Python code cursor_pos : int The location of the cursor in the block where the token should be found """ - names = [] - tokens = [] + names: List[str] = [] + tokens: List[Token] = [] call_names = [] offsets = {1: 0} # lines start at 1 |