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

Antoine Pitrou solipsis at pitrou.net
Thu Jul 7 21:12:17 CEST 2011


On Thu, 7 Jul 2011 15:08:54 -0400
Mike Graham <mikegraham at gmail.com> wrote:
> On Thu, Jul 7, 2011 at 1:43 PM, Antoine Pitrou <solipsis-xNDA5Wrcr86sTnJN9+BGXg at public.gmane.org> 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.

Well, it does sound fundamentally useless!

Regards

Antoine.





More information about the Python-ideas mailing list