[Python-ideas] relaxing keyword usage restrictions

Nick Coghlan ncoghlan at gmail.com
Wed Sep 7 04:47:32 CEST 2011

On Wed, Sep 7, 2011 at 11:57 AM, Barry Warsaw <barry at python.org> wrote:
> On Sep 07, 2011, at 10:21 AM, Nick Coghlan wrote:
>>>> class Foo:
> ...    """I'm still -1 myself, but such a delimited approach at least has the
> ...    virtue of addressing the *entire* scope of the identifier syntax
> ...    limitation rather than singling out keywords for special treatment.
> ...
> ...    Legitimate use cases for such a feature would include at least those
> ...    currently handled by the 'rename' flag on the namedtuple constructor
> ...    (the latter would still be needed to handle duplicate field names,
> ...    but illegal identifiers could just be quoted).
> ...    """ = False
> frightening-ly y'rs,

Even worse:

class Foo:
    '' = True

Utterly untenable :)

It would also be horribly ambiguous in several places where strings
and identifiers are already both allowed, so the full concept fails on
multiple counts.

That means the scope would have to be limited to potentially
supporting string literals on the RHS of the dot operator. Essentially
it would just become further syntactic sugar for the getattr(),
setattr() and delattr() builtins, with the string delimiters remaining
optional for valid identifiers.

I still don't really like the idea, but I have to admit that it would
at least arguably be more elegant than attribute renaming or builtin
function based workarounds for attribute names from external sources
that aren't legal Python identifiers.

As with other recurring discussions, I suggest that someone
particularly interested in the topic put together a PEP so we can
avoid rehashing the same details every couple of years - even rejected
PEPs can serve as useful repositories for the reasons why certain
things *aren't* done.


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

More information about the Python-ideas mailing list