[Python-Dev] Interop between datetime and mxDateTime

Tim Peters tim.one@comcast.net
Wed, 15 Jan 2003 12:59:20 -0500


[M.-A. Lemburg]
> ...
> Doesn't compare use the same coercion scheme as all the other
> operators ? Ie. if datetimeobject.cmp(datetimeobject, otherobject)
> returns NotImplemented, wouldn't otherobject.cmp(datetimeobject,
> otherobject) be called ?

*If* it returned NotImplemented, yes.  But it doesn't return NotImplemented,
it raises TypeError.  This is so that, e.g.,

    date.today() < 12

doesn't *end up* falling back on the default compare-object-addresses
scheme.  Comparison is different than, e.g., + in that way:  there's a
default non-exception-raising implementation of comparison when both objects
return NotImplemented, but the default implementation of addition when both
objects return NotImplemented raises TypeError.

> ...
> Right; provided I can easily test for the datetime types
> at C level. That doesn't seem to be easily possible, though,
> since it requires going through Python to get at the
> type objects.

Patches accepted <wink>.

> ...
> True, but then roundtripping isn't guaranteed for many
> datetime operations anyway. Pretty much the same as with floating
> point arithmetic in general.

Not so for this datetime implementation:  all datetime operations are exact,
except for those that raise OverflowError.