[Python-ideas] Verbatim names (allowing keywords as names)

Stephan Houben stephanh42 at gmail.com
Wed May 16 05:12:29 EDT 2018

Hi all,

One problem already alluded to with the \identifier syntax is that it only
if the old Python version is sufficiently recent to understand \.

What about using parentheses to allow a keyword to be used as an identifier:
(where)(x, y)

This then in combination with allowing keywords in the following
unambiguous locations:
1. After dot ("numpy.where")
2. After def and class ("def where")
3. After "as".

This should make it possible to write code which works in a hypothetical
future Python
version where "where" is a keyword, and which also works with current
Python versions.


2018-05-16 11:03 GMT+02:00 Paul Moore <p.f.moore at gmail.com>:

> On 16 May 2018 at 09:56, Eric V. Smith <eric at trueblade.com> wrote:
> > On 5/16/18 4:47 AM, Eric V. Smith wrote:
> >>
> >> On 5/16/18 4:13 AM, Paul Moore wrote:
> >
> >
> >>> Can you give a worked example of how this would
> >>> help if we wanted to introduce a new keyword? For example, if we
> >>> intended to make "where" a keyword, what would numpy and its users
> >>> need to do to continue using `numpy.where`?
> >>
> >>
> >> I think they'd have to change to `numpy.\where` when `where` became a
> >> keyword.
> >
> >
> > To be clear: this would apply to any code that uses numpy.where, not just
> > the code that defines it.
> >
> > The only way to bullet-proof your code so that it would never need any
> > modifications in the future would be to put a backslash in front of every
> > identifier. Or maybe just all-lowercase identifiers, since we're
> unlikely to
> > make a keyword with uppercase chars in it.
> >
> > And since no one in their right mind would do that, there's still the
> risk
> > of your code breaking in the future. But at least there would be a way of
> > fixing it in a way that would work both with old versions of python where
> > the identifier isn't a keyword, and for versions where it is. That is,
> once
> > "old versions" include ones that support verbatim names.
> That's about what I thought - thanks.
> Paul
> _______________________________________________
> 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/20180516/a40118bf/attachment-0001.html>

More information about the Python-ideas mailing list