Marko Rauhamaa <ma...@pacujo.net>: > Christian Heimes <christ...@python.org>: > >> Python creates a new bound method object every time. A bound method >> object is a callable object that keeps a strong reference to the >> function, class and object. The bound method object adds the object as >> first argument to the function (aka 'self'). > > I stand corrected. I had thought the trampoline ("bound method > object") was created once and for all.
Sure enough. The principle is explicitly specified in <URL: https://docs.python.org/3.2/reference/datamodel.html#index-46>. Thus: >>> class X: ... def f(self): ... print("Hello") ... >>> x = X() >>> x.f() Hello >>> def f(): print("Meh") ... >>> x.f = f >>> x.f() Meh >>> delattr(x, "f") >>> x.f() Hello IOW, you can override a method with setattr() but you cannot delete a method with delattr(). Marko -- https://mail.python.org/mailman/listinfo/python-list