Bug or wart? You make the call.
aleax at aleax.it
Fri Mar 14 15:17:00 CET 2003
Michael Hudson wrote:
> Thomas Wouters <thomas at xs4all.net> writes:
>> It doesn't have an official rationale, but it's easily
>> considered. Python is a very dynamic language. An instance's
>> __class__ and a class's __bases__ can be dynamically changed. It is
>> part of how Python Works.
> Apropos of not much, I was faintly surprised this didn't raise an
> />> class C(object):
> |.. def m(self, x):
> |.. print x
> />> class D(object):
> |.. pass
> ->> o = C()
> ->> m = o.m
> ->> o.__class__ = D
> ->> m(1)
Yes, it IS faintly surprising -- one would expect a check for
isinstance(m.im_self, m.im_class), which, here, would fail.
However, the check is apparently performed only for the explicit
first argument when m.im_self is None, no doubt (?) for reasons
More information about the Python-list