[Python-ideas] Syntax idea: escaping names to avoid keyword ambiguity

Carl Smith carl.input at gmail.com
Mon May 14 16:52:52 EDT 2018


I can only think of three ways to reference a name defined in a different
file: In an import
statement, as properties of objects and as keyword arguments.

Import statements are implicit assignments, so if Python allowed the
following grammar,
you could still import the odd thing that had a reserved name, without
bringing that name
into your local namespace.

    from <keyword> import <keyword> as <name>

Property names always follow a dot, where only a name is valid, so Python
could allow
this too:

    <expression>.<keyword>

Keyword arguments are also generally unambiguous, as they have to appear
within the
parens of an invocation, before the equals sign:

    <expression>(<keyword>=<expression>)

If Python allowed those three examples (but still prevented users from
*defining* names
that are keywords) new keywords could be introduced without breaking old
code , and the
language would only require relatively minor tweaking.

-- Carl Smith
carl.input at gmail.com

On 14 May 2018 at 19:11, Terry Reedy <tjreedy at udel.edu> wrote:

> On 5/14/2018 10:02 AM, Clint Hepner wrote:
>
>>
>> On 2018 May 14 , at 6:47 a, Daniel Moisset <dmoisset at machinalis.com>
>>> wrote:
>>>
>>> Following up some of the discussions about the problems of adding
>>> keywords and Guido's proposal of making tokenization context-dependent, I
>>> wanted to propose an alternate way to go around the problem.
>>>
>>
>> My main objection to what follows is that it doesn't seem to offer any
>> benefit over the current practice of appending an underscore (_) to a
>> keyword to make it a valid identifier.
>>
>
> Tkinter uses this convention for a few option names that clash.
>
> --
> Terry Jan Reedy
>
>
> _______________________________________________
> 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/51b73afe/attachment-0001.html>


More information about the Python-ideas mailing list