[Python-ideas] Make keywords KEYwords only in places they would have syntactical meaning

Nick Coghlan ncoghlan at gmail.com
Sat May 19 01:20:30 EDT 2018

On 19 May 2018 at 04:34, Chris Angelico <rosuav at gmail.com> wrote:

> "yield" would have to be a keyword in any context where an expression
> is valid. Which, in turn, makes it utterly useless as a function name,
> or any other identifier.

Right, I spent a fair bit of time thinking about this in the context of
using "given" to introduce postfix assignment expressions, and while it's
reasonably straightforward to make it so that keywords that can't start an
expression or statement (currently "as", "in", "is", "and", "or") can also
be used as names, we don't have that kind of freedom for keywords that can
*start* an expression or statement ("async"/"await" relied on some parser
tricks that relied on the fact that "async" always needed to be paired with
"def" to introduce a coroutine, and "await EXPR" was only permitted inside
coroutine definitions).

We also run into the problem that even when the compiler can tell the
difference, *humans* are still likely to be confused by the potential
ambiguity (for the same reason that shadowing builtins is generally
considered poor style).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180519/8dc6bb79/attachment.html>

More information about the Python-ideas mailing list