[Python-ideas] Verbatim names (allowing keywords as names)

Greg Ewing greg.ewing at canterbury.ac.nz
Fri May 18 02:45:58 EDT 2018


Carl Smith wrote:
 > I wrote:
>> The trouble with explicitly overriding keywords is that it still  requires old code to
>>  be changed whenever a new keyword is added...
 >
> For the purpose of this discussion, let's say that if any code implicitly
> enables a new feature (by simply using it), all the code in that file is 'new
> code' in the context of the specific feature (a bit like how `yield` works).
> If `until` was a new keyword, any file that used it as a keyword would be new
> code. Any other files are 'old code'.

Okay, that works because it *doesn't* require old code to explicitly
say "I'm using this word the old way". My comment was about the idea
of having to use a backslash to escape keywords used as names, or
similar schemes.

> We would also allow `name.until` and `dance(until="am")` in new code, so that
> we can still reference names in old code (without them becoming names in new
> code).

Actually it would be fine if new code had to say "name.\until" etc.

The only problem I can see is that it would probably be near-impossible
to implement using the current parser generator. It might be doable
by keeping multiple versions of the grammar -- try to parse using the
most recent grammar, if that doesn't work, try the next most recent,
etc. But that would be pretty horrible, and it would require keeping
old cruft in the implementation forever, which we don't like doing.

-- 
Greg



More information about the Python-ideas mailing list