On 18-apr-2006, at 10:49, Guido van Rossum wrote: > On 4/18/06, Greg Ewing <[EMAIL PROTECTED]> wrote: >> The problem is that there's no way for Python to know >> which class the method is "in", in the sense required >> here. >> >> That could be fixed by giving functions defined inside >> a class statement an attribute referring back to the >> class. It would create a circular reference, but that's >> not so much of a problem these days. > > This begs two questions (at least): > > - How would the function be given the attribute? At the time the > function is being defined the class doesn't exist yet; and by the time > the class exists, the function may be wrapped in any number of layers > of decorators which may or may not pass on attribute assignment (most > implementations of decorators I've seen don't -- at best they copy the > attributes that already exist on the function into the wrapper).
And related to this: a function may be used as a method on several classes, storing the attribute on the function is therefore not possible without significantly changing the language. <code> class A (object): pass class B (object): pass def myMethod(self): print "hello from", self.__class__ A.myMethod = myMethod B.myMethod = myMethod A().myMethod() B().myMethod() </code> Ronald _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com