Commit 3cacf427 authored by Christoph Groth's avatar Christoph Groth
Browse files

ensure_isinstance: fix message when a tuple of types is given

parent 8beaa8c3
......@@ -101,11 +101,15 @@ def interleave(seq):
return zip(iseq, iseq)
def ensure_isinstance(obj, typ, msg=None):
if isinstance(obj, typ):
def ensure_isinstance(obj, class_or_tuple, msg=None):
if isinstance(obj, class_or_tuple):
return
if msg is None:
msg = "Expecting an instance of {}.".format(typ.__name__)
if isinstance(class_or_tuple, tuple):
names = ", or ".join(t.__name__ for t in class_or_tuple)
else:
names = class_or_tuple.__name__
msg = "Expecting an instance of {}.".format(names)
raise TypeError(msg)
def ensure_rng(rng=None):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment