Archive for October 26, 2008

Sunday, October 26, 2008

Why Explicit self Has to Stay

Guido van Rossum:

When a method definition is decorated, we don’t know whether to automatically give it a ‘self’ parameter or not: the decorator could turn the function into a static method (which has no ‘self’), or a class method (which has a funny kind of self that refers to a class instead of an instance), or it could do something completely different (it’s trivial to write a decorator that implements ‘@classmethod’ or ‘@staticmethod’ in pure Python). There’s no way without knowing what the decorator does whether to endow the method being defined with an implicit ‘self’ argument or not.

I like explicit self, anyway.