def traverse_imports(names):
 pending = [names]
 while pending:
  node = pending.pop()
  if (node.type == token.NAME):
   (yield node.value)
  elif (node.type == syms.dotted_name):
   (yield ''.join([ch.value for ch in node.children]))
  elif (node.type == syms.dotted_as_name):
   pending.append(node.children[0])
  elif (node.type == syms.dotted_as_names):
   pending.extend(node.children[::(-2)])
  else:
   raise AssertionError('unknown node type')

def traverse_imports ( names ) : pending = [ names ] while pending : node = pending . pop ( ) if ( node . type == token . NAME ) : ( yield node . value ) elif ( node . type == syms . dotted_name ) : ( yield '' . join ( [ ch . value for ch in node . children ] ) ) elif ( node . type == syms . dotted_as_name ) : pending . append ( node . children [ 0 ] ) elif ( node . type == syms . dotted_as_names ) : pending . extend ( node . children [ : : ( - 2 ) ] ) else : raise AssertionError ( 'unknown node type' )
walks over all the names imported in a dotted_as_names node .