[Python-ideas] datetime.timedelta literals

Jacco van Dorp j.van.dorp at deonet.nl
Tue Jun 5 04:22:20 EDT 2018


2018-06-05 10:08 GMT+02:00 Pål Grønås Drange <paal.drange at gmail.com>:
>> You can't import literals. They're syntax, not just bound names.
>
> I'm way out of my comfort zone now, but the parser could for
> `123.45_f`
> give
> `__literal_f__(123.45)`
> and then that function should be imported.
>
> I'm sure this idea has many shortcomings that I don't see, but that was the
> reason why I wanted to import stuff.
>
> Pål

Before your code is executed, python scans your entire file for syntax
errors. Since 123.45_f is currently not a valid literal, it'll just
print a syntax error without even looking at your imports.

To change that, the very core of python would need to look completely
different. It'd be a metric fuckton of work for a whole lot of people.
Im not a core dev myself or anything, but i'm pretty confident that
this isn't going to happen for a rather minor need like this.


More information about the Python-ideas mailing list