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

Stephan Houben stephanh42 at gmail.com
Sun May 13 14:48:17 EDT 2018


Note that Javascript does something similar,
in that reserved keywords are allowed in member access.

var x = {if : 42};
console.log(x.if);

Stephan


2018-05-13 20:42 GMT+02:00 Eric Fahlgren <ericfahlgren at gmail.com>:

> On Sun, May 13, 2018 at 11:20 AM Guido van Rossum <guido at python.org>
> wrote:
>
>> For example, we could allow keywords after 'def' and after a period, and
>> then the following would become legal:
>>
>
> ​Our modeling database overloads getattr/setattr (think SQLAlchemy) to
> allow us to access to database fields as if they were Python data members.
> Nothing new here, but we do have problems with keyword collisions on some
> of the objects, as we are wrapping an already-existing modeling language
> (MSC Adams Solver dataset) with our objects.  We were pleased with 'print'
> became a function, because it removed the restriction from that one, but
> one of the remaining ones is 'return', like this:
>
> class Sensor:
>     def __init__(self):
>         setattr(self, "print", 0)
>         setattr(self, "return", 0)
>
> s = Sensor()
> s.print  # Works now, didn't in Python 2.
> s.return  # Bork.
>
> I have a decades old +1 on this.
>
> _______________________________________________
> 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/20180513/35141c5e/attachment.html>


More information about the Python-ideas mailing list