[Python-ideas] Verbatim names (allowing keywords as names)
Steven D'Aprano
steve at pearwood.info
Thu May 17 08:51:49 EDT 2018
On Thu, May 17, 2018 at 06:03:32PM +1200, Greg Ewing wrote:
> Steven D'Aprano wrote:
> >Let's say you're reading from a CSV file, creating an object from each
> >row, and processing it:
>
> Okay, I can see it could be useful for situations like that.
>
> But this is still a completely different use case from the
> one that started this discussion, which was making it less
> painful to add new keywords to the language. The backslash
> idea doesn't help at all with that.
Doesn't help *at all*?
Sure it does.
It's Python 3.8, and I learn that in 4.0 "spam" is going to become a
keyword. I simply take my code and change all the references spam to
\spam, and I've future-proofed the code for 4.0 while still keeping
compatibility with 3.8 and 3.9.
(But not 3.7 of course. But we can't have everything.)
If my code is a library which others will use, the benefit is even
bigger. (For a purely internal project, I could just replace spam with
spam_ and be done with it.) But for a library, I already have public
documentation saying that my API is the function spam(), and I don't
want to have to change the public API. As far as my library's users are
concerned, nothing has changed.
--
Steve
More information about the Python-ideas
mailing list