def get_user_scope(module, position):
 user_stmt = module.get_statement_for_position(position)
 if (user_stmt is None):
  def scan(scope):
   for s in scope.children:
    if (s.start_pos <= position <= s.end_pos):
     if isinstance(s, (tree.Scope, tree.Flow)):
      return (scan(s) or s)
     elif (s.type in ('suite', 'decorated')):
      return scan(s)
   return None
  return (scan(module) or module)
 else:
  return user_stmt.get_parent_scope(include_flows=True)

def get_user_scope ( module , position ) : user_stmt = module . get_statement_for_position ( position ) if ( user_stmt is None ) : def scan ( scope ) : for s in scope . children : if ( s . start_pos <= position <= s . end_pos ) : if isinstance ( s , ( tree . Scope , tree . Flow ) ) : return ( scan ( s ) or s ) elif ( s . type in ( 'suite' , 'decorated' ) ) : return scan ( s ) return None return ( scan ( module ) or module ) else : return user_stmt . get_parent_scope ( include_flows = True )
returns the scope in which the user resides .