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

Stefan Behnel stefan_ml at behnel.de
Tue Jul 5 06:32:56 CEST 2011


Raymond Hettinger, 05.07.2011 03:55:
>
> On Jul 4, 2011, at 6:26 PM, Greg Ewing wrote:
>
>> Chris Rebert wrote:
>>
>>> Why does it accept nested tuples in the first place for that matter?
>>
>> Probably so that tuples could be used to emulate a "set
>> of types" before we had real sets.
>>
>> Now that we do have real sets, it doesn't seem necessary
>> to continue with this and allow sets of sets, etc. So
>> +1 on leaving tuple as a special case for this and
>> treating all other iterables as flat.
>
> -1 on further garbaging this API by introducing yet another signature variant -- even worse, a signature variant with a special case for the tuple type (didn't we learn our lesson with old-style string formatting).
>
> I have to agree with Benjamin that this proposal would be utterly unnecessary software bloat.

FWIW, another -1 from me. The current API is simple: you pass in either a 
type or a tuple of types. Distinguishing the two cases is easy and safe, 
and even the somewhat bloatish case of passing in a tuple of tuples of 
types is safe, although somewhat complicated already.

This proposal will complicate the implementation for no obvious reason, and 
will introduce slightly weird corner cases, like the handling of iterable 
type objects.

After all, testing for a type multiple times, just because it ended up in 
the type tuple multiple times, will still work correctly. And even if 
repeated testing is not desired for some reason, using tuple(set(x)) 
instead of set(x) won't make that a big difference.

Stefan




More information about the Python-ideas mailing list