def complete_import(prefix, line, start, end, ctx):
 ltoks = line.split()
 ntoks = len(ltoks)
 if ((ntoks == 2) and (ltoks[0] == 'from')):
  return {'{} '.format(i) for i in complete_module(prefix)}
 if ((ntoks > 1) and (ltoks[0] == 'import') and (start == len('import '))):
  return complete_module(prefix)
 if ((ntoks > 2) and (ltoks[0] == 'from') and (ltoks[2] == 'import')):
  try:
   mod = importlib.import_module(ltoks[1])
  except ImportError:
   return set()
  out = {i[0] for i in inspect.getmembers(mod) if i[0].startswith(prefix)}
  return out
 return set()

def complete_import ( prefix , line , start , end , ctx ) : ltoks = line . split ( ) ntoks = len ( ltoks ) if ( ( ntoks == 2 ) and ( ltoks [ 0 ] == 'from' ) ) : return { '{} ' . format ( i ) for i in complete_module ( prefix ) } if ( ( ntoks > 1 ) and ( ltoks [ 0 ] == 'import' ) and ( start == len ( 'import ' ) ) ) : return complete_module ( prefix ) if ( ( ntoks > 2 ) and ( ltoks [ 0 ] == 'from' ) and ( ltoks [ 2 ] == 'import' ) ) : try : mod = importlib . import_module ( ltoks [ 1 ] ) except ImportError : return set ( ) out = { i [ 0 ] for i in inspect . getmembers ( mod ) if i [ 0 ] . startswith ( prefix ) } return out return set ( )
completes module names and contents for "import .