MCPcopy Create free account
hub / github.com/ipython/ipython / module_completion

Function module_completion

IPython/core/completerlib.py:210–239  ·  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

208 get_ipython().set_hook('complete_command',do_complete, str_key = cmd)
209
210def module_completion(line):
211 """
212 Returns a list containing the completion possibilities for an import line.
213
214 The line looks like this :
215 'import xml.d'
216 'from xml.dom import'
217 """
218
219 words = line.split(' ')
220 nwords = len(words)
221
222 # from whatever <tab> -> 'import '
223 if nwords == 3 and words[0] == 'from':
224 return ['import ']
225
226 # 'from xy<tab>' or 'import xy<tab>'
227 if nwords < 3 and (words[0] in {'%aimport', 'import', 'from'}) :
228 if nwords == 1:
229 return get_root_modules()
230 mod = words[1].split('.')
231 if len(mod) < 2:
232 return get_root_modules()
233 completion_list = try_import('.'.join(mod[:-1]), True)
234 return ['.'.join(mod[:-1] + [el]) for el in completion_list]
235
236 # 'from xyz import abc<tab>'
237 if nwords >= 3 and words[0] == 'from':
238 mod = words[1]
239 return try_import(mod)
240
241#-----------------------------------------------------------------------------
242# Completers

Callers 3

test_bad_module_allFunction · 0.90
module_completerFunction · 0.85

Calls 2

get_root_modulesFunction · 0.85
try_importFunction · 0.85

Tested by 2

test_bad_module_allFunction · 0.72