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

Antoine Pitrou solipsis at pitrou.net
Thu Jul 7 19:43:21 CEST 2011


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 ;)

Regards

Antoine.





More information about the Python-ideas mailing list