##// END OF EJS Templates
misc typing
Matthias Bussonnier -
Show More
@@ -144,6 +144,10 b' class PtkHistoryAdapter(History):'
144 144
145 145 """
146 146
147 auto_suggest: UnionType[
148 AutoSuggestFromHistory, NavigableAutoSuggestFromHistory, None
149 ]
150
147 151 def __init__(self, shell):
148 152 super().__init__()
149 153 self.shell = shell
@@ -660,11 +664,9 b' class TerminalInteractiveShell(InteractiveShell):'
660 664 self.alias_manager.soft_define_alias(cmd, cmd)
661 665
662 666
663 def __init__(self, *args, **kwargs):
667 def __init__(self, *args, **kwargs) -> None:
664 668 super(TerminalInteractiveShell, self).__init__(*args, **kwargs)
665 self.auto_suggest: UnionType[
666 AutoSuggestFromHistory, NavigableAutoSuggestFromHistory, None
667 ] = None
669 self.auto_suggest = None
668 670 self._set_autosuggestions(self.autosuggestions_provider)
669 671 self.init_prompt_toolkit_cli()
670 672 self.init_term_title()
@@ -1,7 +1,7 b''
1 1 import re
2 2 import tokenize
3 3 from io import StringIO
4 from typing import Callable, List, Optional, Union, Generator, Tuple
4 from typing import Callable, List, Optional, Union, Generator, Tuple, Sequence
5 5
6 6 from prompt_toolkit.buffer import Buffer
7 7 from prompt_toolkit.key_binding import KeyPressEvent
@@ -63,9 +63,17 b' class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory):'
63 63 ) -> Generator[Tuple[str, float], None, None]:
64 64 """
65 65 text: str
66
66 Text content to find a match for, the user cursor is most of the
67 time at the end of this text.
67 68 skip_lines: float
68 float is used as the base value is +inf
69 number of items to skip in the search, this is used to indicate how
70 far in the list the user has navigated by pressing up or down.
71 The float type is used as the base value is +inf
72 history : History
73 prompt_toolkit History instance to fetch previous entries from.
74 previous : bool
75 Direction of the search, whether we are looking previous match
76 (True), or next match (False).
69 77
70 78 Yields
71 79 ------
@@ -91,7 +99,9 b' class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory):'
91 99 if previous and line_number >= skip_lines:
92 100 return
93 101
94 def _find_next_match(self, text: str, skip_lines: float, history: History):
102 def _find_next_match(
103 self, text: str, skip_lines: float, history: History
104 ) -> Generator[Tuple[str, float], None, None]:
95 105 return self._find_match(text, skip_lines, history, previous=False)
96 106
97 107 def _find_previous_match(self, text: str, skip_lines: float, history: History):
@@ -99,7 +109,7 b' class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory):'
99 109 list(self._find_match(text, skip_lines, history, previous=True))
100 110 )
101 111
102 def up(self, query: str, other_than: str, history: History):
112 def up(self, query: str, other_than: str, history: History) -> None:
103 113 for suggestion, line_number in self._find_next_match(
104 114 query, self.skip_lines, history
105 115 ):
@@ -115,7 +125,7 b' class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory):'
115 125 # no matches found, cycle back to beginning
116 126 self.skip_lines = 0
117 127
118 def down(self, query: str, other_than: str, history: History):
128 def down(self, query: str, other_than: str, history: History) -> None:
119 129 for suggestion, line_number in self._find_previous_match(
120 130 query, self.skip_lines, history
121 131 ):
General Comments 0
You need to be logged in to leave comments. Login now