diff --git a/IPython/terminal/ipapp.py b/IPython/terminal/ipapp.py index df4648b..6280bce 100755 --- a/IPython/terminal/ipapp.py +++ b/IPython/terminal/ipapp.py @@ -156,7 +156,7 @@ frontend_flags['i'] = ( flags.update(frontend_flags) aliases = dict(base_aliases) -aliases.update(shell_aliases) +aliases.update(shell_aliases) # type: ignore[arg-type] #----------------------------------------------------------------------------- # Main classes and functions @@ -180,7 +180,7 @@ class LocateIPythonApp(BaseIPythonApplication): class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp): name = u'ipython' description = usage.cl_usage - crash_handler_class = IPAppCrashHandler + crash_handler_class = IPAppCrashHandler # typing: ignore[assignment] examples = _examples flags = flags diff --git a/IPython/terminal/shortcuts/__init__.py b/IPython/terminal/shortcuts/__init__.py index c4af137..bc0c95c 100644 --- a/IPython/terminal/shortcuts/__init__.py +++ b/IPython/terminal/shortcuts/__init__.py @@ -163,11 +163,11 @@ def create_ipython_shortcuts(shell, for_all_platforms: bool = False): return _preceding_text_cache[pattern] if callable(pattern): - def _preceding_text(): app = get_app() before_cursor = app.current_buffer.document.current_line_before_cursor - return bool(pattern(before_cursor)) + # mypy can't infer if(callable): https://github.com/python/mypy/issues/3603 + return bool(pattern(before_cursor)) # type: ignore[operator] else: m = re.compile(pattern) diff --git a/IPython/terminal/shortcuts/auto_suggest.py b/IPython/terminal/shortcuts/auto_suggest.py index 8c699d8..f623f8e 100644 --- a/IPython/terminal/shortcuts/auto_suggest.py +++ b/IPython/terminal/shortcuts/auto_suggest.py @@ -1,7 +1,7 @@ import re import tokenize from io import StringIO -from typing import Callable, List, Optional, Union +from typing import Callable, List, Optional, Union, Generator, Tuple from prompt_toolkit.buffer import Buffer from prompt_toolkit.key_binding import KeyPressEvent @@ -19,7 +19,11 @@ def _get_query(document: Document): class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory): - """ """ + """ + A subclass of AutoSuggestFromHistory that allow navigation to next/previous + suggestion from history. To do so it remembers the current position, but it + state need to carefully be cleared on the right events. + """ def __init__( self, @@ -56,7 +60,24 @@ class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory): def _find_match( self, text: str, skip_lines: float, history: History, previous: bool - ): + ) -> Generator[Tuple[str, float], None, None]: + """ + text: str + + skip_lines: float + float is used as the base value is +inf + + Yields + ------ + Tuple with: + str: + current suggestion. + float: + will actually yield only ints, which is passed back via skip_lines, + which may be a +inf (float) + + + """ line_number = -1 for string in reversed(list(history.get_strings())): for line in reversed(string.splitlines()):