[Python-ideas] Before and after the colon in funciton defs.

Ron Adam ron3200 at gmail.com
Fri Sep 16 23:30:47 CEST 2011

(This idea may have been suggested before, because it seems too obvious
to me.)

How about if we remove the requirement that the colon be on the same
line as the function name.

And, what if the colon is then used to split the difference between the
definition time, and call time code in function definitions.  So that
every thing before the colon is done at definition time.  Everything
after the colon is done at call time.

def foo(...):
   """ doc string """ 
   <function body>

Then could become ...

def foo(...)
   """ doc string """     # foo.__doc__ = """ doc string """
   <function body>

I think this represents what is actually happening a bit better.

One possibility for define time code is to have decorators listed that
read in the order they are applied instead of bottom up.

def foo(n)
    """ function to be decorated. """
    @deco1        # foo = deco1(foo)  The '@' notation still works.
    @deco2        # foo = deco2(foo)
    <function body>

Note, that putting the doc string after the decorators may be better as
it would put the doc string on the decorated function instead of the

I think there may be more things possible with this idea than the simple
cases above.


More information about the Python-ideas mailing list