In Python you have the None
singleton, which acts pretty oddly in certain circumstances:
>>> a = None
>>> type(a)
None
is not a type, it is the singleton instance itself - and the second argument of isinstance must be a type, class or tuple of them. Hence, you need to use NoneType
from types.
from types import NoneType
print isinstance(None, NoneType)
print isinstance(None, (NoneType, str, float))
True True
Although, I would often be inclined to replace isinstance(x, (NoneType, str, float))
with x is None or isinstance(x, (str, float))
.