def _higher_function_scope(node):
 current = node
 while (current.parent and (not isinstance(current.parent, nodes.Function))):
  current = current.parent
 if (current and current.parent):
  return current.parent

def _higher_function_scope ( node ) : current = node while ( current . parent and ( not isinstance ( current . parent , nodes . Function ) ) ) : current = current . parent if ( current and current . parent ) : return current . parent
search for the first function which encloses the given scope .