[Python-3000] Removing 'self' from method definitions (original) (raw)
Ronald Oussoren ronaldoussoren at mac.com
Tue Apr 18 10:56:28 CEST 2006
- Previous message: [Python-3000] Removing 'self' from method definitions
- Next message: [Python-3000] Removing 'self' from method definitions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 18-apr-2006, at 10:49, Guido van Rossum wrote:
On 4/18/06, Greg Ewing <greg.ewing at canterbury.ac.nz> 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.
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()
Ronald
- Previous message: [Python-3000] Removing 'self' from method definitions
- Next message: [Python-3000] Removing 'self' from method definitions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]