Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
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))