[Python-ideas] Enhance definition of functions

Antoine Pitrou solipsis at pitrou.net
Fri Aug 2 19:46:24 CEST 2013


On Fri, 2 Aug 2013 09:25:05 -0700
Andrew Barnert <abarnert at yahoo.com> wrote:
> On Aug 2, 2013, at 9:00, Antoine Pitrou <solipsis at pitrou.net> wrote:
> 
> >> Using "@" as the marker character is also problematic, since the
> >> following degenerate case will probably confuse the parser (due to it
> >> looking too much like a decorator clause):
> >> 
> >>   @something() given:
> >>       ...
> > 
> > No, that would simply be forbidden. In this proposal, "@" can only mark
> > names of parameters in function calls. We already reuse "*" and "**"
> > for a specific meaning in front of function call parameters, so there's
> > a precedent for such polysemy.
> 
> That's fine if callbacks are the _only_ case you want to handle, but as Nick just explained, there are many other cases that are also useful. The middle of an if expression in a comprehension, for example, isn't a function parameter.

There may be many other cases, but almost any time people complain
about the lack of inline functions, it's in situations where they are
declaring callbacks (i.e. GUI- or network-programming). So, yes, I
don't think the other use cases should be a primary point of concern.

> Also, when you have a long function call expression--as you almost always
> do in, say, PyObjC or PyWin32 GUIs--you often want to put each
> parameter on its own line. While that won't confuse the parser, it
> could easily confuse a human, who will see "@callback," on a line by
> itself and think "decorator".

Even if indented, inside a parenthesis and not preceding a similarly
indented "def"?

Regards

Antoine.




More information about the Python-ideas mailing list