[Python-ideas] Crazy idea: allow keywords as names in certain positions

Rob Cliffe rob.cliffe at btinternet.com
Sun May 13 14:59:49 EDT 2018


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).
So you would be allowing "second class" identifiers - legal in some 
positions where an identifier is allowed, not legal in others.
With respect, that seems like a terrible idea; neither those who want to 
use such identifiers, nor those who don't, would be happy.  Especially 
if it encourages work-arounds such as

     def and(x, y):
         return ...

#   and(1,2)           #  Oops, SyntaxError.  Oh, I know:
     globals()['and'](1,2)    # Works!

and a zillion others.
>
> [snip] And it would probably cause certain typos be harder to diagnose.
No doubt.
>
> I should also mention that this was inspired from some messages where 
> Tim Peters berated the fashion of using "reserved words", waxing 
> nostalgically about the old days of Fortran (sorry, FORTRAN), which 
> doesn't (didn't?) have reserved words at all (nor significant 
> whitespace, apart from the "start in column 7" rule).
>
> Anyway, just throwing this out. Please tear it apart!
Thanks. :-)
>
> -- 
> --Guido van Rossum (python.org/~guido <http://python.org/%7Eguido>)
>
Best wishes
Rob Cliffe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180513/00d8277e/attachment-0001.html>


More information about the Python-ideas mailing list