[Python-ideas] Allow isinstance second argument to be a set of types
Alexander Belopolsky
alexander.belopolsky at gmail.com
Wed Jul 6 20:09:48 CEST 2011
On Mon, Jul 4, 2011 at 5:50 PM, Michael Foord <fuzzyman at gmail.com> wrote:
..
>> I'm ambivalent, as long as the implementation is careful to make sure
>> one can still use isinstance on classes like these:
>>
>> class WeirdMetaclass(type):
>> def __iter__(self):
>> yield 1
>>
>> class MyObject(metaclass=WeirdMetaclass):
>> pass
>>
>> It still feels a little dirty though, to have to pick between options
>> that are not mutually exclusive.
>
> That's a more reasonable objection for not accepting arbitrary iterables
I don't see a problem here. If classinfo is a type, isinstance should
not attempt to iterate over it. If one really wants to check for
membership in the list that MyObject yields, it is always possible to
do it explicitly: isinstance(x, list(MyObject)).
More information about the Python-ideas
mailing list