[Python-Dev] Let's get rid of unbound methods
Shane Holloway (IEEE)
shane.holloway at ieee.org
Wed Jan 5 17:44:31 CET 2005
Alex Martelli wrote:
> def f(*a): pass class C(object): pass class D(object): pass C.f = D.f
> = f
>
> If now we want C.f.im_class to differ from D.f.im_class then we need
> f to get copied implicitly when it's assigned to C.f (or, of course,
> when C.f is accessed... but THAT might be substantial overhead). OK,
> I guess, as long as we don't expect any further attribute setting on
> f to affect C.f or D.f (and I don't know of any real use case where
> that would be needed).
You'd have to do a copy anyway, because f() is still a module-level
callable entity. I also agree with Glyph that im_class should only
really be set in the case of methods defined within the class block.
Also, interestingly, removing unbound methods makes another thing possible.
class A(object):
def foo(self): pass
class B(object):
foo = A.foo
class C(object):
pass
C.foo = A.foo
I'd really like to avoid making copies of functions for the sake of
reload() and edit-and-continue functionality. Currently we can track
down everything that has a reference to foo, and replace it with newfoo.
With copies, this would more difficult.
Thanks,
-Shane
More information about the Python-Dev
mailing list