[Python-ideas] datetime.timedelta literals

Paul Moore p.f.moore at gmail.com
Mon Jun 4 03:58:23 EDT 2018


On 4 June 2018 at 07:44, Pål Grønås Drange <paal.drange at gmail.com> wrote:
>> I'm not entirely sure what point you're trying to make here, but you
>> quoted that section somewhat out of context.
>>
>> [...]
>>
>> That seems directly relevant here. I'm not aware of a "timedelta
>> users" community, nor is there a particular package (or set of
>> packages) other than the stdlib datetime module, that constitute "best
>> of breed" practice when handling timedeltas. So taking my full quote,
>> I'd have to say that you seem to have undermined your own proposal
>> here.
>
> Yes, that was why I quoted it; I thought I should bring the relevant
> parts of the discussion into this, even if they were against this
> proposal.
>
>> For what it's worth, I use the datetime module and timedeltas
>> regularly, and I [...] don't support the proposal.
>
> That's good to hear, but if you don't mind asking, is your lack of
> support because you use timedelta "programatically" instead of
> hard-coded time units, or is there a different (or more) reason(s)?
>
> (I'm ready to yield, now I'm just curious.)

I don't know what you mean by "programatically instead of hard-coded
time units". In my code, I've never felt the need to be able to write
something like "5min" rather than "timedelta(minutes=5)". Far from it
- I find the former jarring, whereas the latter is perfectly clear, so
even if the literal form were available I probably wouldn't use it
much. I don't see what problem they solve, I've *never* heard anyone
claim that using the constructor to create a timedelta object was a
problem - even in your proposal you don't explicitly claim that
(although I presume you do think that, otherwise why bother making the
proposal?).

The point of my original comment that you quoted was more to say that
*if* a specialist community with expertise in a particular area
exists, and they claim that there is benefit to a notation, then their
expert knowledge can override the more general view (which is
typically pretty conservative, for good reasons). In this case,
there's no such expert community, so there's no reason not to go with
the default position (which in this case could be summarised as "if
none of decimals, scale suffixes or physical units managed to make a
case for dedicated literal syntax, timedelta doesn't stand a chance").

Paul


More information about the Python-ideas mailing list