[Python-Dev] Review of Issue http://bugs.python.org/issue2706, timedelta operators

Tennessee Leeuwenburg tleeuwenburg at gmail.com
Tue Mar 10 06:34:15 CET 2009


Hi all,

I'm just trying to find my feet with regards to the proper process for
reviewing. I'm not sure what's best:
  * Post the review as a comment on the associated issue. Only nosies will
be updated.
  * Post the review as a comment on the issue, then post a one-line
information update to this list
  * Post the review to this list for consideration
  * ???? other

http://bugs.python.org/issue2706
General topic: Math operations on timedelta objects
Last activity: 12 Dec 08
Original owner: webograph

This issue covers a number of discrete functional changes. I here review
each in turn:

1) Allow truediv, the operator '/', to be applied to two timedeltas (e.g.
td1 / td2). The return value is a float representing the number of times
that td2 goes into td1.

Evaluation: Since both time deltas are quantitative values of the same unit,
it makes sense they should be able to support basic math operations. In this
case, operation to be added is '/' or truediv. I would personally find this
functionality useful, and believe it is a natural addition to the code.

Recommendation: That this functionality be recommended for development

2) Allow truediv to be applied to a timedelta and an int or float. The
return value is a timedelta representing the fractional proportion of the
original timedelta.

Evaluation: This makes total sense.
Recommendation: That this functionality be recommended for development

2) Allow divmod, the operator '%', to be applied to two timedeltas (e.g. td1
% td2). I think there is some debate here about whether the return value be
an integer in microsends, or a timedelta. I personally believe that a
timedelta should be returned, representing the amount of time remaining
after (td1 // td2)  * td2 has been subtracted.

The alternative is an integer, but due to a lack of immediate clarity over
what time quanta this integer represents, I would suggest returning a unit
amount. There is also some discussion of returning (long, timedelta), but I
personally fail to see the merits of returning the long without some unit
attached.

3) Allow divmod, the operator '%', to be applied to a timedelta and an
integer or float. (e.g. <timedelta> % 3). I'm not quite as sold on this.  I
suggest that more discussion is required to flesh this out further.


A patch has been attached which implements some of this behaviour. I would
suggest that it's valuable to start doing this work in discrete chunks so
that progress can be begun before the issues under debate are resolved. I
suggest that it would be appropriate to create three smaller issues, each
tackling just one piece of functionality. This should make the changes more
atomic and the code patch simpler.

-T

-- 
--------------------------------------------------
Tennessee Leeuwenburg
http://myownhat.blogspot.com/
"Don't believe everything you think"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090310/40de2897/attachment.htm>


More information about the Python-Dev mailing list