def unpack_rect(rect):
    """Unpack the size and raise a type error if needed."""
    if (not hasattr(rect, '__iter__') or
            len(rect) != 2 or
            not isinstance(rect[0], int) or
            not isinstance(rect[1], int)):
        raise TypeError("expected tuple of two integers but got %r"
                        % type(rect))
    return rect