Show More
@@ -156,7 +156,7 b" frontend_flags['i'] = (" | |||||
156 | flags.update(frontend_flags) |
|
156 | flags.update(frontend_flags) | |
157 |
|
157 | |||
158 | aliases = dict(base_aliases) |
|
158 | aliases = dict(base_aliases) | |
159 | aliases.update(shell_aliases) |
|
159 | aliases.update(shell_aliases) # type: ignore[arg-type] | |
160 |
|
160 | |||
161 | #----------------------------------------------------------------------------- |
|
161 | #----------------------------------------------------------------------------- | |
162 | # Main classes and functions |
|
162 | # Main classes and functions | |
@@ -180,7 +180,7 b' class LocateIPythonApp(BaseIPythonApplication):' | |||||
180 | class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp): |
|
180 | class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp): | |
181 | name = u'ipython' |
|
181 | name = u'ipython' | |
182 | description = usage.cl_usage |
|
182 | description = usage.cl_usage | |
183 | crash_handler_class = IPAppCrashHandler |
|
183 | crash_handler_class = IPAppCrashHandler # typing: ignore[assignment] | |
184 | examples = _examples |
|
184 | examples = _examples | |
185 |
|
185 | |||
186 | flags = flags |
|
186 | flags = flags |
@@ -163,11 +163,11 b' def create_ipython_shortcuts(shell, for_all_platforms: bool = False):' | |||||
163 | return _preceding_text_cache[pattern] |
|
163 | return _preceding_text_cache[pattern] | |
164 |
|
164 | |||
165 | if callable(pattern): |
|
165 | if callable(pattern): | |
166 |
|
||||
167 | def _preceding_text(): |
|
166 | def _preceding_text(): | |
168 | app = get_app() |
|
167 | app = get_app() | |
169 | before_cursor = app.current_buffer.document.current_line_before_cursor |
|
168 | before_cursor = app.current_buffer.document.current_line_before_cursor | |
170 | return bool(pattern(before_cursor)) |
|
169 | # mypy can't infer if(callable): https://github.com/python/mypy/issues/3603 | |
|
170 | return bool(pattern(before_cursor)) # type: ignore[operator] | |||
171 |
|
171 | |||
172 | else: |
|
172 | else: | |
173 | m = re.compile(pattern) |
|
173 | m = re.compile(pattern) |
@@ -1,7 +1,7 b'' | |||||
1 | import re |
|
1 | import re | |
2 | import tokenize |
|
2 | import tokenize | |
3 | from io import StringIO |
|
3 | from io import StringIO | |
4 | from typing import Callable, List, Optional, Union |
|
4 | from typing import Callable, List, Optional, Union, Generator, Tuple | |
5 |
|
5 | |||
6 | from prompt_toolkit.buffer import Buffer |
|
6 | from prompt_toolkit.buffer import Buffer | |
7 | from prompt_toolkit.key_binding import KeyPressEvent |
|
7 | from prompt_toolkit.key_binding import KeyPressEvent | |
@@ -19,7 +19,11 b' def _get_query(document: Document):' | |||||
19 |
|
19 | |||
20 |
|
20 | |||
21 | class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory): |
|
21 | class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory): | |
22 |
""" |
|
22 | """ | |
|
23 | A subclass of AutoSuggestFromHistory that allow navigation to next/previous | |||
|
24 | suggestion from history. To do so it remembers the current position, but it | |||
|
25 | state need to carefully be cleared on the right events. | |||
|
26 | """ | |||
23 |
|
27 | |||
24 | def __init__( |
|
28 | def __init__( | |
25 | self, |
|
29 | self, | |
@@ -56,7 +60,24 b' class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory):' | |||||
56 |
|
60 | |||
57 | def _find_match( |
|
61 | def _find_match( | |
58 | self, text: str, skip_lines: float, history: History, previous: bool |
|
62 | self, text: str, skip_lines: float, history: History, previous: bool | |
59 | ): |
|
63 | ) -> Generator[Tuple[str, float], None, None]: | |
|
64 | """ | |||
|
65 | text: str | |||
|
66 | ||||
|
67 | skip_lines: float | |||
|
68 | float is used as the base value is +inf | |||
|
69 | ||||
|
70 | Yields | |||
|
71 | ------ | |||
|
72 | Tuple with: | |||
|
73 | str: | |||
|
74 | current suggestion. | |||
|
75 | float: | |||
|
76 | will actually yield only ints, which is passed back via skip_lines, | |||
|
77 | which may be a +inf (float) | |||
|
78 | ||||
|
79 | ||||
|
80 | """ | |||
60 | line_number = -1 |
|
81 | line_number = -1 | |
61 | for string in reversed(list(history.get_strings())): |
|
82 | for string in reversed(list(history.get_strings())): | |
62 | for line in reversed(string.splitlines()): |
|
83 | for line in reversed(string.splitlines()): |
General Comments 0
You need to be logged in to leave comments.
Login now