Yes. The whole idea of OOD is to decouple internal representation from
external behavior.
The *whole* idea? You don't think that encapsulation and inheritance
might also be involved? *wink*
Besides, there's a difference between internal _representation_ and
internal _implementation_. I don't always choose my words carefully, but
this was one of those times
A timedelta object *represents* a delta as (days + seconds +
microseconds). That is part of the interface, not implementation. How it
is actually implemented is irrelevant. (If I were to take a wild guess,
I'd predict that timedeltas record the total number of seconds.)
That's what __repr__() is for.
Actually, __repr__ should, if practical, match the constructor for the
object:
py> import datetime
py> t = datetime.timedelta(2, 3)
py> eval(repr(t)) == t
True
Yes, I know that's what the docs say. That's why it's not an
implementation bug. It's a design bug
I don't think it is. Given a timedelta object with D days, S seconds and
M microseconds, I think that it is a very useful property if the string
also says it has D days, S seconds and M microseconds. Would you not
agree? I think that this would be silly:
str(timedelta(1, 0, 0))
=> '0 day, 24:01:-5184000.0'
even though it would be correct. So we can dismiss the idea that the str
of a timedelta should be free to arbitrarily vary from the internal
representation.
I consider this to be a useful constraint on timedelta's internal
representation (not implementation): the seconds and microseconds should
be normalised to the half-open intervals, 0 to 86400 for seconds and 0 to
1000000 for microseconds. Given that constraint, and the previous
constraint that strings should show the same number of days etc., and we
have the current behaviour.
Both constraints are reasonable. You have to weaken one, or the other, in
order to get the result you want. That's not necessarily unreasonable,
but neither is it a given. Python-Dev is not normally "braindead", so at
least given them the benefit of the doubt that *maybe* there's some good
reason we haven't thought of.