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

Jim Jewett jimjjewett at gmail.com
Sun Sep 18 21:32:34 CEST 2011

On Sat, Sep 17, 2011 at 2:16 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> Specifically targeting existing uses of the default argument hack, on
> the other hand, comes with at least 3 already known use cases (i.e.
> name lookup micro-optimisation, early binding semantics and shared
> state for algorithms). People already tolerate messing with the
> function signature to obtain those behaviours, so it's reasonable to
> wonder if it is possible to provide a cleaner way to obtain the same
> effect. A simple set of definition time name bindings would likely
> suffice without greatly increasing the language complexity or the
> runtime overhead of function calls.

Since the goal is to add some context, like a wrapper, it seems
reasonable to use a specialization of @.  @+ suggests adding something
to the environment, and won't be ambiguous unless numbers become

    def decorating_function(user_function):

I would personally be fine with a restriction to @+name=<expr> but I
suppose others might prefer a tuple, like

    @+(tuple, sorted, len, KeyError)=(tuple, sorted, len, KeyError)
    def decorating_function(user_function):


More information about the Python-ideas mailing list