Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 46c503d

Browse files
committed
MISC docs, cleanup and typing (in progress).
1 parent 2e0a730 commit 46c503d

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

IPython/terminal/ipapp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def make_report(self,traceback):
156156
flags.update(frontend_flags)
157157

158158
aliases = dict(base_aliases)
159-
aliases.update(shell_aliases)
159+
aliases.update(shell_aliases) # type: ignore[arg-type]
160160

161161
#-----------------------------------------------------------------------------
162162
# Main classes and functions
@@ -180,7 +180,7 @@ def start(self):
180180
class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):
181181
name = u'ipython'
182182
description = usage.cl_usage
183-
crash_handler_class = IPAppCrashHandler
183+
crash_handler_class = IPAppCrashHandler # typing: ignore[assignment]
184184
examples = _examples
185185

186186
flags = flags

IPython/terminal/shortcuts/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ def preceding_text(pattern: Union[str, Callable]):
163163
return _preceding_text_cache[pattern]
164164

165165
if callable(pattern):
166-
167166
def _preceding_text():
168167
app = get_app()
169168
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]
171171

172172
else:
173173
m = re.compile(pattern)

IPython/terminal/shortcuts/auto_suggest.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
import tokenize
33
from io import StringIO
4-
from typing import Callable, List, Optional, Union
4+
from typing import Callable, List, Optional, Union, Generator, Tuple
55

66
from prompt_toolkit.buffer import Buffer
77
from prompt_toolkit.key_binding import KeyPressEvent
@@ -19,7 +19,11 @@ def _get_query(document: Document):
1919

2020

2121
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+
"""
2327

2428
def __init__(
2529
self,
@@ -56,7 +60,24 @@ def get_suggestion(
5660

5761
def _find_match(
5862
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+
"""
6081
line_number = -1
6182
for string in reversed(list(history.get_strings())):
6283
for line in reversed(string.splitlines()):

0 commit comments

Comments
 (0)