[Python-ideas] Crazy idea: allow keywords as names in certain positions
tjreedy at udel.edu
Mon May 14 14:04:49 EDT 2018
On 5/13/2018 2:19 PM, Guido van Rossum wrote:
> The idea I had (not for the first time :-) is that in many syntactic
> positions we could just treat keywords as names, and that would free up
> these keywords.
This trades the simplicity of 'using a keyword as an identifier always
fails immediately' for the flexibility of 'using a keyword as an
identifier may work, or may fail later'. The failure would be
predictable in the sense of being being deterministic for any particular
code string but unpredictable in the sense of not knowing what code
would be written. It would also be unpredictable when people use a
keyword as variable without knowing that they had done so.
The proposal reminds me of the current tkinter situation when using
tcl/tk compiled without thread support: calling a tkinter function
(method) from worker threads may work, at least initially, but may
eventually fail. The main problem here is that this is not documented.
But I suspect that if and when it is
(https://bugs.python.org/issue33479), most will 'not do that' and only a
few intrepid souls will do the necessary experiments.
The impact on real-time syntax coloring should be considered. An
re-based colorizer, like IDLE's, tags every appearance of keywords
outside of strings and comments, syntactically correct or not. For
instance, the first two 'and's in "a and b.and # and error" are tagged.
To not tag the second would require full parsing, presumably by
compiling to AST, and more support code. I suspect this would would
make coloring slower. Whether too slow for existing machines, I don't know.
Terry Jan Reedy
More information about the Python-ideas