[Python-ideas] Make all keywords legal as an attribute name

Mike Meyer mwm at mired.org
Tue Apr 26 08:42:00 CEST 2011

On Mon, 25 Apr 2011 16:26:47 -0400
Mike Graham <mikegraham at gmail.com> wrote:
> Other examples, some more contrived than others, could be
> provided--some of these would be good names if not for their keyword
> status. However, I don't think I've seen a suggestion better than the
> current solution (or lack thereof).

I think the *first* part of this proposal - allowing attribute names
to be keywords - provides almost all the benefits and few of the
problems that were brought up.

For instance, the "with .with.as as .as" goes away - the worst you can
do is "with with_.as as as_", which is only slightly worse than the
already legal "with with_.as_ as as_".

I don't think it changes the cognitive load of someone reading or
writing code noticeably - limiting it to attributes means you're
limiting it to a namespace that's already visually and logically
distinct from the namespace that keywords can appear in. In fact, that
separation also means there are no backwards compatibility issues.

On the other hand, the problem of wanting to bind external names (say
from a CORBA ORB) should go away, because the names tend to be
attributes of the external objects you are using. The objects
themselves you get to name.

Likewise, most of the examples from the standard library where the
obvious name for something was a keyword were attribute names. This
would fix those, but not let the first parameter to classmethods be

The nasty problem - possibly nasty enough to kill this - are the cases
where context allows bare names to be used to refer to things that are
used as attributes outside the context: a modules global namespace and
class variables off the top of my head. Using the bare name as a
keyword would be a syntax error, but using it as an attribute
elsewhere would work fine. Class variables can probably be worked
around since they only use for bare names is to initialize them at
class definition time, but module global are another issue.

Mike Meyer <mwm at mired.org>		http://www.mired.org/consulting.html
Independent Software developer/SCM consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

More information about the Python-ideas mailing list