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

Method fetch_completions

Lib/idlelib/autocomplete.py:161–217  ·  view source on GitHub ↗

Return a pair of lists of completions for something. The first list is a sublist of the second. Both are sorted. If there is a Python subprocess, get the comp. list there. Otherwise, either fetch_completions() is running in the subprocess itself or it was called in

(self, what, mode)

Source from the content-addressed store, hash-verified

159 complete, mode, wantwin)
160
161 def fetch_completions(self, what, mode):
162 """Return a pair of lists of completions for something. The first list
163 is a sublist of the second. Both are sorted.
164
165 If there is a Python subprocess, get the comp. list there. Otherwise,
166 either fetch_completions() is running in the subprocess itself or it
167 was called in an IDLE EditorWindow before any script had been run.
168
169 The subprocess environment is that of the most recently run script. If
170 two unrelated modules are being edited some calltips in the current
171 module may be inoperative if the module was not the last to run.
172 """
173 try:
174 rpcclt = self.editwin.flist.pyshell.interp.rpcclt
175 except:
176 rpcclt = None
177 if rpcclt:
178 return rpcclt.remotecall("exec", "get_the_completion_list",
179 (what, mode), {})
180 else:
181 if mode == ATTRS:
182 if what == "": # Main module names.
183 namespace = {**__main__.__builtins__.__dict__,
184 **__main__.__dict__}
185 bigl = eval("dir()", namespace)
186 bigl.extend(completion_kwds)
187 bigl.sort()
188 if "__all__" in bigl:
189 smalll = sorted(eval("__all__", namespace))
190 else:
191 smalll = [s for s in bigl if s[:1] != '_']
192 else:
193 try:
194 entity = self.get_entity(what)
195 bigl = dir(entity)
196 bigl.sort()
197 if "__all__" in bigl:
198 smalll = sorted(entity.__all__)
199 else:
200 smalll = [s for s in bigl if s[:1] != '_']
201 except:
202 return [], []
203
204 elif mode == FILES:
205 if what == "":
206 what = "."
207 try:
208 expandedpath = os.path.expanduser(what)
209 bigl = os.listdir(expandedpath)
210 bigl.sort()
211 smalll = [s for s in bigl if s[:1] != '.']
212 except OSError:
213 return [], []
214
215 if not smalll:
216 smalll = bigl
217 return smalll, bigl
218

Callers 3

open_completionsMethod · 0.95

Calls 6

get_entityMethod · 0.95
remotecallMethod · 0.80
expanduserMethod · 0.80
listdirMethod · 0.80
extendMethod · 0.45
sortMethod · 0.45

Tested by 1