MCPcopy Index your code
hub / github.com/python/cpython / get_completions

Method get_completions

Lib/_pyrepl/readline.py:138–169  ·  view source on GitHub ↗
(self, stem: str)

Source from the content-addressed store, hash-verified

136 return "".join(b[p + 1 : self.pos])
137
138 def get_completions(self, stem: str) -> tuple[list[str], CompletionAction | None]:
139 module_completions = self.get_module_completions()
140 if module_completions is not None:
141 return module_completions
142 if len(stem) == 0 and self.more_lines is not None:
143 b = self.buffer
144 p = self.pos
145 while p > 0 and b[p - 1] != "\n":
146 p -= 1
147 num_spaces = 4 - ((self.pos - p) % 4)
148 return [" " * num_spaces], None
149 result = []
150 function = self.config.readline_completer
151 if function is not None:
152 try:
153 stem = str(stem) # rlcompleter.py seems to not like unicode
154 except UnicodeEncodeError:
155 pass # but feed unicode anyway if we have no choice
156 state = 0
157 while True:
158 try:
159 next = function(stem, state)
160 except Exception:
161 break
162 if not isinstance(next, str):
163 break
164 result.append(next)
165 state += 1
166 # Emulate readline's sorting using the visible text rather than
167 # the raw ANSI escape sequences used for colorized matches.
168 result.sort(key=stripcolor)
169 return result, None
170
171 def get_module_completions(self) -> tuple[list[str], CompletionAction | None] | None:
172 line = self.get_line()

Calls 5

strFunction · 0.85
functionFunction · 0.50
appendMethod · 0.45
sortMethod · 0.45