##// 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 def __init__(self, shell):
151 def __init__(self, shell):
148 super().__init__()
152 super().__init__()
149 self.shell = shell
153 self.shell = shell
@@ -660,11 +664,9 b' class TerminalInteractiveShell(InteractiveShell):'
660 self.alias_manager.soft_define_alias(cmd, cmd)
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 super(TerminalInteractiveShell, self).__init__(*args, **kwargs)
668 super(TerminalInteractiveShell, self).__init__(*args, **kwargs)
665 self.auto_suggest: UnionType[
669 self.auto_suggest = None
666 AutoSuggestFromHistory, NavigableAutoSuggestFromHistory, None
667 ] = None
668 self._set_autosuggestions(self.autosuggestions_provider)
670 self._set_autosuggestions(self.autosuggestions_provider)
669 self.init_prompt_toolkit_cli()
671 self.init_prompt_toolkit_cli()
670 self.init_term_title()
672 self.init_term_title()
@@ -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, Generator, Tuple
4 from typing import Callable, List, Optional, Union, Generator, Tuple, Sequence
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
@@ -62,10 +62,18 b' class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory):'
62 self, text: str, skip_lines: float, history: History, previous: bool
62 self, text: str, skip_lines: float, history: History, previous: bool
63 ) -> Generator[Tuple[str, float], None, None]:
63 ) -> Generator[Tuple[str, float], None, None]:
64 """
64 """
65 text: str
65 text : str
66
66 Text content to find a match for, the user cursor is most of the
67 skip_lines: float
67 time at the end of this text.
68 float is used as the base value is +inf
68 skip_lines : float
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 Yields
78 Yields
71 ------
79 ------
@@ -91,7 +99,9 b' class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory):'
91 if previous and line_number >= skip_lines:
99 if previous and line_number >= skip_lines:
92 return
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 return self._find_match(text, skip_lines, history, previous=False)
105 return self._find_match(text, skip_lines, history, previous=False)
96
106
97 def _find_previous_match(self, text: str, skip_lines: float, history: History):
107 def _find_previous_match(self, text: str, skip_lines: float, history: History):
@@ -99,7 +109,7 b' class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory):'
99 list(self._find_match(text, skip_lines, history, previous=True))
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 for suggestion, line_number in self._find_next_match(
113 for suggestion, line_number in self._find_next_match(
104 query, self.skip_lines, history
114 query, self.skip_lines, history
105 ):
115 ):
@@ -115,7 +125,7 b' class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory):'
115 # no matches found, cycle back to beginning
125 # no matches found, cycle back to beginning
116 self.skip_lines = 0
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 for suggestion, line_number in self._find_previous_match(
129 for suggestion, line_number in self._find_previous_match(
120 query, self.skip_lines, history
130 query, self.skip_lines, history
121 ):
131 ):
General Comments 0
You need to be logged in to leave comments. Login now