Antwort: Re: Some language proposals. ['LBBW': checked]
jepler at unpythonic.net
Thu Feb 26 14:50:54 CET 2004
On Thu, Feb 26, 2004 at 10:36:17AM +0100, Holger Joukl wrote:
> Well, there is no bug at all, as far as I can see. Runs in my interpreter.
I think that the person you were replying to (whose name you kindly
removed, so I have no idea who it was) was trying to refer to this
>>> class A: pass
>>> def f(): pass
>>> A.f = f; assert A.f is f
The statement "A.f = f" sets A.__dict__['f'] = f. The statement 'A.f is
f' calls type(A).__getattribute__, which returns an "unbound method
I won't argue that this behavior isn't surprising (since apparently it
surprised somebody) but it's because of this behavior that the following
def f(self): pass
a = A()
.. if A.f returned something other than an unbound method object, then
it would also be legal to call 'A.f(0)' when 0 is not an instance of A.
If the OP wants to add a function to A that is not treated as a normal
method, then he can use the 'staticmethod' wrapper.
>>> A.f = staticmethod(f)
>>> A.f is f
More information about the Python-list