[Python-3000] Removing 'self' from method definitions

Michael Chermside mcherm at mcherm.com
Thu Apr 13 21:58:31 CEST 2006


Ian Bicking writes:
> I propose that the self argument be removed from method definitions.

This is not a new proposal. The fundamental problem is a perceived
mismatch between the argument list used for calling and the argument
list used in defining the method. Of the many times that it has been
proposed, the best syntax I have seen was as follows:

    def self.my_method(arg1, arg2):
        # body goes here

In other words, make the definition look like the invocation. In
this proposal "self" is not magical, it is simply declared in a
slightly different location. The syntax would be used by sensible
people only when defining methods, but there would be no such
rule enforced by the interpreter, nor would the existing syntax
be broken or prohibited.

To be abundantly specific, the proposal is that if the next two tokens
after a "def" were "self" and "." then the result of compiling such
code would be exactly the same as if they were not present but "self"
and "," were inserted immediately after the opening parenthesis.
Whether to allow any identifier or only the particular identifier
"self" is an interesting question that I would leave for Guido.

Personally, I favor doing this. I think that making declarations look
similar to invocations is very useful.

-- Michael Chermside



More information about the Python-3000 mailing list