[Python-Dev] Let's get rid of unbound methods (original) (raw)
Jack Diederich jack at performancedrivers.com
Tue Jan 4 19:42:17 CET 2005
- Previous message: [Python-Dev] Let's get rid of unbound methods
- Next message: [Python-Dev] Let's get rid of unbound methods
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Jan 04, 2005 at 10:28:03AM -0800, Guido van Rossum wrote:
In my blog I wrote:
Let's get rid of unbound methods. When class C defines a method f, C.f should just return the function object, not an unbound method that behaves almost, but not quite, the same as that function object. The extra type checking on the first argument that unbound methods are supposed to provide is not useful in practice (I can't remember that it ever caught a bug in my code) and sometimes you have to work around it; it complicates function attribute access; and the overloading of unbound and bound methods on the same object type is confusing. Also, the type checking offered is wrong, because it checks for subclassing rather than for duck typing. Does anyone think this is a bad idea? Anyone want to run with it? I like the idea, it means I can get rid of this[1]
func = getattr(cls, 'do_command', None) setattr(cls, 'do_command', staticmethod(func.im_func)) # don't let anyone on c.l.py see this
.. or at least change the comment grin,
-Jack
[1] http://cvs.sourceforge.net/viewcvs.py/lyntin/lyntin40/sandbox/leantin/mudcommands.py?view=auto
- Previous message: [Python-Dev] Let's get rid of unbound methods
- Next message: [Python-Dev] Let's get rid of unbound methods
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]