From f6cb59f82a748f6225e8f9460722c8169a00d665 2023-01-08 14:45:38 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: 2023-01-08 14:45:38 Subject: [PATCH] Fix mypy job, fix issues detected by mypy --- diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 52f3e79..c7fa22c 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -29,11 +29,13 @@ jobs: pip install mypy pyflakes flake8 - name: Lint with mypy run: | + set -e mypy -p IPython.terminal mypy -p IPython.core.magics mypy -p IPython.core.guarded_eval mypy -p IPython.core.completer - name: Lint with pyflakes run: | + set -e flake8 IPython/core/magics/script.py flake8 IPython/core/magics/packaging.py diff --git a/IPython/terminal/shortcuts/__init__.py b/IPython/terminal/shortcuts/__init__.py index 6bc6ec7..68eaf65 100644 --- a/IPython/terminal/shortcuts/__init__.py +++ b/IPython/terminal/shortcuts/__init__.py @@ -11,7 +11,7 @@ import signal import sys import re import os -from typing import Callable +from typing import Callable, Dict, Union from prompt_toolkit.application.current import get_app @@ -143,10 +143,10 @@ def create_ipython_shortcuts(shell, for_all_platforms: bool = False): return paired focused_insert = (vi_insert_mode | emacs_insert_mode) & has_focus(DEFAULT_BUFFER) - _preceding_text_cache = {} - _following_text_cache = {} + _preceding_text_cache: Dict[Union[str, Callable], Condition] = {} + _following_text_cache: Dict[Union[str, Callable], Condition] = {} - def preceding_text(pattern): + def preceding_text(pattern: Union[str, Callable]): if pattern in _preceding_text_cache: return _preceding_text_cache[pattern] @@ -383,8 +383,8 @@ def create_ipython_shortcuts(shell, for_all_platforms: bool = False): self._input_mode = mode if shell.editing_mode == "vi" and shell.modal_cursor: - ViState._input_mode = InputMode.INSERT - ViState.input_mode = property(get_input_mode, set_input_mode) + ViState._input_mode = InputMode.INSERT # type: ignore + ViState.input_mode = property(get_input_mode, set_input_mode) # type: ignore return kb diff --git a/IPython/terminal/shortcuts/auto_match.py b/IPython/terminal/shortcuts/auto_match.py index 0976bb2..bb0ca8b 100644 --- a/IPython/terminal/shortcuts/auto_match.py +++ b/IPython/terminal/shortcuts/auto_match.py @@ -50,7 +50,7 @@ def raw_string_parenthesis(event: KeyPressEvent): r".*(r|R)[\"'](-*)", event.current_buffer.document.current_line_before_cursor, ) - dashes = matches.group(2) or "" + dashes = matches.group(2) if matches else "" event.current_buffer.insert_text("()" + dashes) event.current_buffer.cursor_left(len(dashes) + 1) @@ -61,7 +61,7 @@ def raw_string_bracket(event: KeyPressEvent): r".*(r|R)[\"'](-*)", event.current_buffer.document.current_line_before_cursor, ) - dashes = matches.group(2) or "" + dashes = matches.group(2) if matches else "" event.current_buffer.insert_text("[]" + dashes) event.current_buffer.cursor_left(len(dashes) + 1) @@ -72,7 +72,7 @@ def raw_string_braces(event: KeyPressEvent): r".*(r|R)[\"'](-*)", event.current_buffer.document.current_line_before_cursor, ) - dashes = matches.group(2) or "" + dashes = matches.group(2) if matches else "" event.current_buffer.insert_text("{}" + dashes) event.current_buffer.cursor_left(len(dashes) + 1)