[Python-ideas] Allow isinstance second argument to be a set of types

MRAB python at mrabarnett.plus.com
Mon Jul 4 02:51:02 CEST 2011


On 03/07/2011 23:47, Michael Foord wrote:
> Hello all,
>
> Occasionally I build up tuples of types for passing as the second
> argument to isinstance. I've noticed on occasions having duplicates, for
> example the following code is Python 2 & 3 compatible but results in a
> duplicate on one of them:
>
> FunctionTypes = (
>      # python function
>      type(create_autospec),
>      # instance method
>      type(ANY.__eq__),
>      # unbound method
>      type(_ANY.__eq__),
> )
>
> It would feel cleaner to me if I could make FunctionTypes a set and use
> that as the second argument to isinstance. :-)
>
Why not just do FunctionTypes = tuple(set(FunctionTypes))?

Or instead of just a tuple or set, an iterable.



More information about the Python-ideas mailing list