def get_nearest_attr_name(pos, rect):
    """Return the rect's attribute name nearest to position.

    This function is used to reposition pop up menus aligned
    in relation to the nearest points (corners or midpoints)
    of the area whose boundaries they respect (this area is
    usually the screen itself, but the user may have
    specified a different area upon instantiation of the
    menu).

    Parameters
    ==========

    pos (2-tuple of integers)
        represents a position in 2d space, the values of
        the x and y axes, respectively.

    rect (pygame.Rect instance)
        represent the area wherein the position is located.
    """

    ### iterate over each attribute name, calculating the
    ### distance of each respective point from the position
    ### in the 'pos' variable; such distance and attribute
    ### name must be gathered together as a tuple and
    ### appended to a list

    ## create list to hold tuples
    distance_attr_pairs = []

    for attr_name in RECT_ATTR_NAMES:

        ## get distance

        distance = get_straight_distance(getattr(rect, attr_name), pos)

        ## create and append tuple with distance and
        ## attribute name
        distance_attr_pairs.append((distance, attr_name))

    ### get pair with smaller distance from pos, that is,
    ### the nearest point
    pair = min(distance_attr_pairs)

    ### return the attr name (index 1)
    return pair[1]
Return the rect's attribute name nearest to position.

    This function is used to reposition pop up menus aligned
    in relation to the nearest points (corners or midpoints)
    of the area whose boundaries they respect (this area is
    usually the screen itself, but the user may have
    specified a different area upon instantiation of the
    menu).

    Parameters
    ==========

    pos (2-tuple of integers)
        represents a position in 2d space, the values of
        the x and y axes, respectively.

    rect (pygame.Rect instance)
        represent the area wherein the position is located.
    
nodezator/menu/common.py