def is_tuple(obj, len_=None):
    """Checks whether given object is a tuple.

    :param len_: Optional expected length of the tuple

    :return: ``True`` if argument is a tuple (of given length, if any),
             ``False`` otherwise
    """
    if not isinstance(obj, tuple):
        return False

    if len_ is None:
        return True
    if not isinstance(len_, Integral):
        raise TypeError(
            "length must be a number (got %s instead)" % type(len_).__name__)
    if len_ < 0:
        raise ValueError("length must be positive (got %s instead)" % len_)

    return len(obj) == len_