[Python-ideas] @return?

Jim Jewett jimjjewett at gmail.com
Thu Apr 15 01:24:12 CEST 2010


On Wed, Apr 14, 2010 at 6:07 PM, Mathias Panzenböck
<grosser.meister.morti at gmx.net> wrote:

> Maybe only allow them [function definitions] at certain places
> where they can be seen as an
> extension to an already existing statement syntax (not to an
> expression syntax):

> foo.bar = def(egg, spam):
>        pass

There have been some proposals to allow dotted names and/or indexes in
place of the name, so that would be written as

    def foo.bar(egg, spam):
        pass

They haven't been permanently rejected, but they've been put on hold
for the same reason class decorators were -- once allowed, they can't
be backed out, so lets wait until we're *sure* we need them.

> return def(egg, spam):
>        pass

This is really only useful inside another function, and isn't a clear
win.  (Would you return the function, or the result of calling the
function?  Could you put () after the definition to call it?  Could
you use other decorators?  Could you put a comma after the definition
to return a tuple of the function and something?)

And note that today's idiom is merely sub-optimal, not outright
terrible.  You can still use your own short name instead of the long
one you need for an external API.

    def wrap():
        def _(egg, spam)
            pass
        return _

-jJ



More information about the Python-ideas mailing list