How to use the ubiquerg.is_collection_like function in ubiquerg

To help you get started, we’ve selected a few ubiquerg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pepkit / peppy / peppy / utils.py View on Github external
def is_null_like(x):
    """
    Determine whether an object is effectively null.

    :param object x: Object for which null likeness is to be determined.
    :return bool: Whether given object is effectively "null."
    """
    return x in [None, ""] or \
        (is_collection_like(x) and isinstance(x, Sized) and 0 == len(x))
github pepkit / peppy / peppy / utils.py View on Github external
def type_check_strict(obj, ts):
    """
    Perform a type check for given object.

    :param object obj: object to type check
    :param Iterable[type] | type ts: collection of types (or just one),
        one of which the given object must be an instance of
    :raise TypeError: if the given object is an instance of none of the given
        types
    :raise Exception: if alleged collection of types is not a non-string
        collection-like type
    """
    if isinstance(ts, type):
        ts = [ts]
    elif not is_collection_like(ts):
        raise Exception("Not a collection of types: {}".format(ts))
    if not isinstance(obj, tuple(ts)):
        raise TypeError("{} ({}) is none of {}".format(obj, type(obj), ts))