MCPcopy Index your code
hub / github.com/ipython/ipython / module_completion

Function module_completion

IPython/core/completerlib.py:238–267  ·  view source on GitHub ↗

Returns a list containing the completion possibilities for an import line. The line looks like this : 'import xml.d' 'from xml.dom import'

(line)

Source from the content-addressed store, hash-verified

236 get_ipython().set_hook('complete_command',do_complete, str_key = cmd)
237
238def module_completion(line):
239 """
240 Returns a list containing the completion possibilities for an import line.
241
242 The line looks like this :
243 'import xml.d'
244 'from xml.dom import'
245 """
246
247 words = line.split(' ')
248 nwords = len(words)
249
250 # from whatever <tab> -> 'import '
251 if nwords == 3 and words[0] == 'from':
252 return ['import ']
253
254 # 'from xy<tab>' or 'import xy<tab>'
255 if nwords < 3 and (words[0] in {'%aimport', 'import', 'from'}) :
256 if nwords == 1:
257 return get_root_modules()
258 mod = words[1].split('.')
259 if len(mod) < 2:
260 return get_root_modules()
261 completion_list = try_import('.'.join(mod[:-1]), True)
262 return ['.'.join(mod[:-1] + [el]) for el in completion_list]
263
264 # 'from xyz import abc<tab>'
265 if nwords >= 3 and words[0] == 'from':
266 mod = words[1]
267 return try_import(mod)
268
269#-----------------------------------------------------------------------------
270# Completers

Callers 4

test_bad_module_allFunction · 0.90
module_completerFunction · 0.85

Calls 2

get_root_modulesFunction · 0.85
try_importFunction · 0.85

Tested by 3

test_bad_module_allFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…