Python Forum
isinstance() arg2 is limited to a type or a tuple of types - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: isinstance() arg2 is limited to a type or a tuple of types (/thread-22889.html)



isinstance() arg2 is limited to a type or a tuple of types - Skaperen - Dec-01-2019

isinstance() arg2 is limited to a type or a tuple of types. it won't even accept a list of types.


RE: isinstance() arg2 is limited to a type or a tuple of types - Larz60+ - Dec-02-2019

I always use isinstance when I want to identify a particular type, not a range of types.


RE: isinstance() arg2 is limited to a type or a tuple of types - Skaperen - Dec-02-2019

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.


RE: isinstance() arg2 is limited to a type or a tuple of types - Larz60+ - Dec-02-2019

2. I rarely need it. When programming, I think binary.


RE: isinstance() arg2 is limited to a type or a tuple of types - buran - Dec-02-2019

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


RE: isinstance() arg2 is limited to a type or a tuple of types - Skaperen - Dec-02-2019

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.