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

Casey Duncan casey@zope.com
Wed, 20 Mar 2002 13:59:03 -0700


Guido van Rossum wrote:
>>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 would never have been able last night's problem if type() had
> returned NoneType -- as it was, it showed that what I had in my hand
> was a wrapper, and that was enough of a clue to unravel the mystery.

Yeah, it's always good to have functions that always behave the way god 
intended. However, once you allow ppl to overload one thing...they want 
to moon 8^)

> __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].

-Casey