From 87ab1c596345fa71c06449a02beec88e98799372 2023-10-27 10:00:13 From: Matthias Bussonnier Date: 2023-10-27 10:00:13 Subject: [PATCH] please linter --- diff --git a/IPython/__main__.py b/IPython/__main__.py index 8e9f989..3b46056 100644 --- a/IPython/__main__.py +++ b/IPython/__main__.py @@ -2,13 +2,13 @@ # encoding: utf-8 """Terminal-based IPython entry point. """ -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # Copyright (c) 2012, IPython Development Team. # # Distributed under the terms of the Modified BSD License. # # The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- from IPython import start_ipython diff --git a/IPython/core/inputsplitter.py b/IPython/core/inputsplitter.py index 1905218..33ed563 100644 --- a/IPython/core/inputsplitter.py +++ b/IPython/core/inputsplitter.py @@ -337,7 +337,7 @@ class InputSplitter(object): # Code object corresponding to the current source. It is automatically # synced to the source, so it can be queried at any time to obtain the code # object; it will be None if the source doesn't compile to valid Python. - code:Optional[CodeType] = None + code: Optional[CodeType] = None # Private attributes @@ -346,9 +346,9 @@ class InputSplitter(object): # Command compiler _compile: codeop.CommandCompiler # Boolean indicating whether the current block is complete - _is_complete:Optional[bool] = None + _is_complete: Optional[bool] = None # Boolean indicating whether the current block has an unrecoverable syntax error - _is_invalid:bool = False + _is_invalid: bool = False def __init__(self) -> None: """Create a new InputSplitter instance.""" diff --git a/IPython/core/inputtransformer.py b/IPython/core/inputtransformer.py index 29ca348..bb1061e 100644 --- a/IPython/core/inputtransformer.py +++ b/IPython/core/inputtransformer.py @@ -71,8 +71,8 @@ class InputTransformer(metaclass=abc.ABCMeta): """ @functools.wraps(func) def transformer_factory(**kwargs): - return cls(func, **kwargs) # type: ignore [call-arg] - + return cls(func, **kwargs) # type: ignore [call-arg] + return transformer_factory class StatelessInputTransformer(InputTransformer): @@ -194,7 +194,7 @@ def assemble_logical_lines(): line = ''.join(parts) # Utilities -def _make_help_call(target:str, esc:str, lspace:str) -> str: +def _make_help_call(target: str, esc: str, lspace: str) -> str: """Prepares a pinfo(2)/psearch call from a target name and the escape (i.e. ? or ??)""" method = 'pinfo2' if esc == '??' \ @@ -212,17 +212,19 @@ def _make_help_call(target:str, esc:str, lspace:str) -> str: # These define the transformations for the different escape characters. -def _tr_system(line_info:LineInfo): +def _tr_system(line_info: LineInfo): "Translate lines escaped with: !" cmd = line_info.line.lstrip().lstrip(ESC_SHELL) return '%sget_ipython().system(%r)' % (line_info.pre, cmd) -def _tr_system2(line_info:LineInfo): + +def _tr_system2(line_info: LineInfo): "Translate lines escaped with: !!" cmd = line_info.line.lstrip()[2:] return '%sget_ipython().getoutput(%r)' % (line_info.pre, cmd) -def _tr_help(line_info:LineInfo): + +def _tr_help(line_info: LineInfo): "Translate lines escaped with: ?/??" # A naked help line should just fire the intro help screen if not line_info.line[1:]: @@ -230,7 +232,8 @@ def _tr_help(line_info:LineInfo): return _make_help_call(line_info.ifun, line_info.esc, line_info.pre) -def _tr_magic(line_info:LineInfo): + +def _tr_magic(line_info: LineInfo): "Translate lines escaped with: %" tpl = '%sget_ipython().run_line_magic(%r, %r)' if line_info.line.startswith(ESC_MAGIC2): @@ -241,17 +244,20 @@ def _tr_magic(line_info:LineInfo): t_magic_name = t_magic_name.lstrip(ESC_MAGIC) return tpl % (line_info.pre, t_magic_name, t_magic_arg_s) -def _tr_quote(line_info:LineInfo): + +def _tr_quote(line_info: LineInfo): "Translate lines escaped with: ," return '%s%s("%s")' % (line_info.pre, line_info.ifun, '", "'.join(line_info.the_rest.split()) ) -def _tr_quote2(line_info:LineInfo): + +def _tr_quote2(line_info: LineInfo): "Translate lines escaped with: ;" return '%s%s("%s")' % (line_info.pre, line_info.ifun, line_info.the_rest) -def _tr_paren(line_info:LineInfo): + +def _tr_paren(line_info: LineInfo): "Translate lines escaped with: /" return '%s%s(%s)' % (line_info.pre, line_info.ifun, ", ".join(line_info.the_rest.split())) @@ -266,9 +272,8 @@ tr = { ESC_SHELL : _tr_system, ESC_PAREN : _tr_paren } @StatelessInputTransformer.wrap -def escaped_commands(line:str): - """Transform escaped commands - %magic, !system, ?help + various autocalls. - """ +def escaped_commands(line: str): + """Transform escaped commands - %magic, !system, ?help + various autocalls.""" if not line or line.isspace(): return line lineinf = LineInfo(line) @@ -342,7 +347,7 @@ def ends_in_comment_or_string(src): @StatelessInputTransformer.wrap -def help_end(line:str): +def help_end(line: str): """Translate lines with ?/?? at the end""" m = _help_end_re.search(line) if m is None or ends_in_comment_or_string(line): @@ -357,7 +362,7 @@ def help_end(line:str): @CoroutineInputTransformer.wrap -def cellmagic(end_on_blank_line:bool=False): +def cellmagic(end_on_blank_line: bool = False): """Captures & transforms cell magics. After a cell magic is started, this stores up any lines it gets until it is diff --git a/IPython/utils/py3compat.py b/IPython/utils/py3compat.py index 34af4c5..66ef337 100644 --- a/IPython/utils/py3compat.py +++ b/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/IPython/utils/text.py b/IPython/utils/text.py index 09204a7..9b653dc 100644 --- a/IPython/utils/text.py +++ b/IPython/utils/text.py @@ -629,7 +629,7 @@ def _col_chunks(l, max_rows, row_first=False): yield l[i:(i + max_rows)] -def _find_optimal(rlist, row_first:bool, separator_size:int, displaywidth:int): +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))) @@ -652,7 +652,9 @@ def _get_or_default(mylist, i, default=None): return mylist[i] -def compute_item_matrix(items, row_first:bool=False, empty=None,*, separator_size=2, displaywidth=80) -> Tuple[List[List[int]], Dict[str, int]] : +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 @@ -707,8 +709,13 @@ def compute_item_matrix(items, row_first:bool=False, empty=None,*, separator_si 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'] + 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: @@ -742,14 +749,21 @@ def columnize(items, row_first=False, separator=" ", displaywidth=80, spread=Fa category=PendingDeprecationWarning, ) if not items: - return '\n' - matrix:List[List[int]] - 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: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' + 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/IPython/utils/timing.py b/IPython/utils/timing.py index 7d8f750..d87e5fa 100644 --- a/IPython/utils/timing.py +++ b/IPython/utils/timing.py @@ -24,7 +24,7 @@ import time try: import resource except ModuleNotFoundError: - resource = None #type: ignore [assignment] + 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/IPython/utils/tokenutil.py b/IPython/utils/tokenutil.py index 36c5c40..6b99a58 100644 --- a/IPython/utils/tokenutil.py +++ b/IPython/utils/tokenutil.py @@ -24,7 +24,9 @@ def generate_tokens(readline): return -def generate_tokens_catch_errors(readline, extra_errors_to_catch:Optional[List[str]]=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", @@ -33,7 +35,7 @@ def generate_tokens_catch_errors(readline, extra_errors_to_catch:Optional[List[s 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:List[TokenInfo] = [] + tokens: List[TokenInfo] = [] try: for token in tokenize.generate_tokens(readline): tokens.append(token) @@ -86,7 +88,8 @@ def line_at_cursor(cell, cursor_pos=0): line = "" return (line, offset) -def token_at_cursor(cell:str, cursor_pos:int=0): + +def token_at_cursor(cell: str, cursor_pos: int = 0): """Get the token at a given cursor Used for introspection. @@ -101,8 +104,8 @@ def token_at_cursor(cell:str, cursor_pos:int=0): cursor_pos : int The location of the cursor in the block where the token should be found """ - names:List[str] = [] - tokens:List[Token] = [] + names: List[str] = [] + tokens: List[Token] = [] call_names = [] offsets = {1: 0} # lines start at 1