[Python-ideas] relaxing keyword usage restrictions

Nick Coghlan ncoghlan at gmail.com
Mon Sep 5 07:50:20 CEST 2011

On Mon, Sep 5, 2011 at 3:18 PM, Mike Meyer <mwm at mired.org> wrote:
> However, there may be some merit to the basic idea. In particular, allowing class to be used as a method parameter has an obvious use case (class methods), and would not produce those confusing cases you used as examples.

The main advantage of making things out-and-out keywords is that it
greatly simplifies the task of *parsing* the language. It's a
trade-off between occasional inconvenience in users having to choose
slightly clunky variable and attribute names (such as 'cls', 'class_'
or 'klass') and the simplicity Python parser developers gain by
defining certain words as keywords that can never appear as variable

One benefit users gain directly from that simplicity is that it makes
syntax highlighters more likely to work correctly - the highlighters
can just always mark keywords as keywords, without needing to worry
about the usage context.

It's easy to say "hey, let's allow keywords to be identifiers in
places where they aren't being used as syntax". However, it doesn't
look like such a great idea when you start considering the amount of
change that would be needed to update the likes CPython, PyPy,
IronPython, Jython, Cython/Pyrex, assorted syntax highlighting rules
for various editors, Pygments, etc, etc.

So, not impossible, but not worth the hassle either, especially since
it would actually make the language *harder* to learn. Learning not to
use keywords as variable names is fairly easy. Learning the ins and
outs of when pseudo-keywords could be used as identifiers and when
they were disallowed would be annoying.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list