In the following snippet:
In [1]: x = [0]
In [2]: isinstance(x, list)
Out[2]: True
In [3]: isinstance(x, (list, set))
Out[3]: True
In [4]: isinstance(x, [list, set])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-95dd12d6777a> in <module>()
----> 1 isinstance(x, [list, set])
TypeError: isinstance() arg 2 must be a type or tuple of types
Why does isinstance
in [4]
insist on the second argument being a tuple, and not just an iterable (e.g. a list
or a set
)? Seems like a weird design decision.