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

Carl Smith carl.input at gmail.com
Sun May 13 22:30:59 EDT 2018


New Python versions already use backwards incompatible syntax, but it has
to be a strict superset so the new parser still parses old code. If a new
Python version introduced syntax that would break old code, it would still
work, so long as the parser knew which syntax the file contained, and was
able to parse both versions.

I personally think Python 3 should have always had a new file extension
(mainly to help editors disambiguate), but some kind of directive at the
top of the file would work as well, a bit like JavaScript's Strict Mode.

The killer objection is that you have to maintain two parsers or some kind
of mashup, but still, the old syntax would be frozen, there could be a lot
of reuse in the front end, and there would still only be one VM.

I'm not hoping this happens any time soon, but if was a choice between devs
maintaining two parsers or users migrating to Python 4, as a user...


-- Carl Smith
carl.input at gmail.com

On 14 May 2018 at 02:28, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:

> Rob Cliffe via Python-ideas wrote:
>
>>     def and(x, y):
>>         return ...
>>
>> #   and(1,2)           #  Oops, SyntaxError.  Oh, I know:
>>     globals()['and'](1,2)    # Works!
>>
>
> If the rule I proposed for "import" were extended to "def"
> then and(1,2) would work. The usual way of using "and" would
> no longer work in that module, but this just goes to show
> that redefining "and" is a silly thing to do in the first
> place.
>
> Redefining the existing keywords could perhaps be forbidden
> if you really want to protect people from shooting themselves
> in the kidneys this particular way.
>
>
> --
> Greg
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180514/0350f011/attachment-0001.html>


More information about the Python-ideas mailing list