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

Mike Graham mikegraham at gmail.com
Thu Jul 7 21:08:54 CEST 2011


On Thu, Jul 7, 2011 at 1:43 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Thu, 7 Jul 2011 13:22:33 -0400
> Jim Jewett <jimjjewett at gmail.com> wrote:
>> On Wed, Jul 6, 2011 at 7:35 PM, Benjamin Peterson <benjamin-+ZN9ApsXKcEdnm+yROfE0A at public.gmane.org> wrote:
>>
>> > class Evil(type):
>> >    def __iter__(self):
>> >        return range(42)
>>
>> > class Accomplice(metaclass=Evil):
>> >    pass
>>
>> ... leading to isinstance(x, 42) rather than isinstance(x, Evil) if
>> the iterable check is done too soon.
>
> In what way is that a problem?
> That you can trigger exceptions by writing malicious code doesn't sound
> like a particularly novel event ;)

I think people are assuming that an iterable metaclass isn't
fundamentally wrong.

Mike



More information about the Python-ideas mailing list