[Zope3-dev] Re: Overloading 'is' (was: Nasty bugs)

Guido van Rossum guido@python.org
Wed, 20 Mar 2002 17:06:55 -0500


[Casey]
> >>A possible change to python where a class could define an __is__ slot 
> > 
> > Hm, I'm not sure I really like to allow overloading 'is'.  It sorta
> > against all expectations.  Ditto for type().
> 
> Yeah you could get some even nastier bugs to happen probably. I just 
> thought it was a better alternative than making Python "Wrapper Aware". 
> That seemed way too application specific. At least this was general.

I'd much rather have an exception against wrapping None -- that catches
probably 95% of the uses of 'is'.

> > __class__ is different -- you're allowed to overload that, and in fact
> > I believe it's a bug that isinstance(x, C) doesn't believe x.__class__
> > (at least it doesn't when C is a new-style class or a built-in type).
> 
> Hmmm. Perhaps fixing this behavior would be enough, that coupled with 
> not wrapping primitives. That just leaves the issue of wrapped mutables 
> and possibly tuples when using `is'. However, you could/should probably 
> treat {}, [] & () as primitives. I'm not sure you would use `is' with 
> non-empty sequences anyhow.
> 
> At any rate I do think getting isinstance to `believe' an overloaded 
> __class__ would be a good thing[tm].

I'll fix that in 2.3.

--Guido van Rossum (home page: http://www.python.org/~guido/)