Bug or wart? You make the call.

Michael Hudson mwh at python.net
Fri Mar 14 10:15:47 EST 2003


Alex Martelli <aleax at aleax.it> writes:

> Michael Hudson wrote:
> 
> > Apropos of not much, I was faintly surprised this didn't raise an
> > exception:
> > 
> > />> class C(object):
> > |..  def m(self, x):
> > |..   print x
> > \__
> > />> class D(object):
> > |..  pass
> > \__
> > ->> o = C()
> > ->> m = o.m
> > ->> o.__class__ = D
> > ->> m(1)
> > 1
> 
> Yes, it IS faintly surprising -- one would expect a check for
> isinstance(m.im_self, m.im_class), which, here, would fail.

You could get away with m.im_self.__class__ is m.im_class.  I think.
I always get confused with this stuff...

> However, the check is apparently performed only for the explicit
> first argument when m.im_self is None, no doubt (?) for reasons of
> performance.

Also possibly because Guido didn't consider this scenario when he was
writing this bit of the interpreter.

I don't know how serious a wart to consider this.  Probably not very.

Cheers,
M.

-- 
  at any rate, I'm satisfied that not only do they know which end of
  the pointy thing to hold, but where to poke it for maximum effect.
                                  -- Eric The Read, asr, on google.com




More information about the Python-list mailing list