Python Forum

Full Version: isinstance() arg2 is limited to a type or a tuple of types
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
isinstance() arg2 is limited to a type or a tuple of types. it won't even accept a list of types.
I always use isinstance when I want to identify a particular type, not a range of types.
what do you mean by "not a range of types"?

1. you use something else for a range of type.

2, you never do a range of types.
2. I rarely need it. When programming, I think binary.
Any practical reason to supply container of container of types? It's either single type or multiple types in which case container (e.g. list, tuple, etc.) of types is enough. Just unpack your nested structure.

Sorry, I misread the question
i coded this:
def istype(a,b):
    x=type(a)
    return x is b or x in b
in this function, arg2 can be any container type supported by the RHS of in.