[Python-3000] Bound and unbound methods

Talin talin at acm.org
Sun Aug 13 13:30:00 CEST 2006


One of the items in PEP 3100 is getting rid of unbound methods. I want 
to explore a heretical notion, which is getting rid of bound methods as 
well.

Now, to be honest, I rather like bound methods. I like being able to 
capture a method call, store it in a variable, and call it later.

However, I also realize that requiring every access to a class variable 
to instantiate a new method object is expensive, to say the least.

Calling a callable would not require a bound method - the 'self' 
parameter would be just another argument. User-defined functions would 
then be no different from native built-in functions or other callables.

You would still need some way to explicitly bind a method if you wanted 
to store it in a variable, perhaps using something like the various 
wrappers in module 'functional'. It would be extra typing, but for me at 
least its not something I do very often, and it would at least have the 
virtue that the intent of the code would be more visually obvious. 
(Also, I tend to find, in my code at least, that I more often use 
closures to accomplish the same thing, which are both clearer to read 
and more powerful.)

Now, one remaining problem to be solved is whether or not to pass 'self' 
as an argument to the resulting callable. I suppose that could be 
handled by inspecting the attributes of the callable and adding the 
extra 'self' argument at the last minute if its not a static method. I 
suspect such tests would be relatively fast, much less than the time 
needed to instantiate and initialize a new method object.

Anyway, I just wanted to throw that out there. Feel free to -1 away... :)

-- Talin


More information about the Python-3000 mailing list