On 13/05/2018 19:19, Guido van Rossum wrote:
As anyone still following the inline assignment discussion knows, a
problem with designing new syntax is that it's hard to introduce new
keywords into the language, since all the nice words seem to be used
as method names in popular packages. (E.g. we can't use 'where'
because there's numpy.where
<https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.where.html>,
and we can't use 'given' because it's used in Hypothesis
<http://hypothesis.readthedocs.io/en/latest/quickstart.html>.)
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.
For example, we could allow keywords after 'def' and after a period,
and then the following would become legal:
class C:
def and(self, other):
return ...
a = C()
b = C()
print(a.and(b))
This does not create syntactic ambiguities because after 'def' and
after a period the grammar *always* requires a NAME.
There are other positions where we could perhaps allow this, e.g. in a
decorator, immediately after '@' (the only keyword that's
*syntactically* legal here is 'not', though I'm not sure it would ever
be useful).
This would not prevent code breakage when a new keyword was added. It
would only reduce the amount of code broken. Although in my
unsubstantiated opinion not by very much; I suspect that most of the
time an identifier is used in a module, it is used at least once in
contexts where it would still be a SyntaxError if it were a keyword.
Rob Cliffe
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/