alias method definitions / syntactic sugar suggestion

Tennessee Leeuwenburg tleeuwenburg at
Fri Mar 6 03:17:00 CET 2009

I'm not sure if this problem I face affects many other people, but I'll just
describe it and see what kind of feedback I get.

I have a suggestion for a new piece of Python syntax when defining methods.
I have seen the following done, and have done it myself

class FanstasticClass:

    def __init__(self):

    def someFantasticMethod(self, argument = True):
        print argument

    justAsFantastic = someFantasticMethod

In order to set up a second method, justAsFantastic, which is just an alias
to someFantasticMethod

The shortcoming of this approach is that supposing we have some unfamiliar
codebase. In my method I see a call to someObject.justAsFantastic("Wahoo").
In order to find that method, I do a file search for "def justAsFantastic("
in order to make sure (a) I only get method definitions and (b) I don't get
any extraneous methods.

This is especially relevant to methods which might be commonly used as
variable names elsewhere in the code.

I suggest allowing the following syntax:

   def justAsFantastic = someFantasticMethod

which will *do* exactly the same thing, but by a syntactic marker that the
variable justAsFantastic points to a method.

Comments appreciated!

Tennessee Leeuwenburg
"Don't believe everything you think"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list