]> granicus.if.org Git - python/commit
date and datetime comparison: when we don't know how to
authorTim Peters <tim.peters@gmail.com>
Fri, 24 Jan 2003 22:36:34 +0000 (22:36 +0000)
committerTim Peters <tim.peters@gmail.com>
Fri, 24 Jan 2003 22:36:34 +0000 (22:36 +0000)
commit8d81a012efa7fde5e43b8ea7275c7fc995cf74fa
tree4fad231a65954388e45221d5ca5a3013897e7efa
parentcd63e619b4703ed5701589d367cccb7357d67aa8
date and datetime comparison:  when we don't know how to
compare against "the other" argument, we raise TypeError,
in order to prevent comparison from falling back to the
default (and worse than useless, in this case) comparison
by object address.

That's fine so far as it goes, but leaves no way for
another date/datetime object to make itself comparable
to our objects.  For example, it leaves Marc-Andre no way
to teach mxDateTime dates how to compare against Python
dates.

Discussion on Python-Dev raised a number of impractical
ideas, and the simple one implemented here:  when we don't
know how to compare against "the other" argument, we raise
TypeError *unless* the other object has a timetuple attr.
In that case, we return NotImplemented instead, and Python
will give the other object a shot at handling the
comparison then.

Note that comparisons of time and timedelta objects still
suffer the original problem, though.
Doc/lib/libdatetime.tex
Lib/test/test_datetime.py
Misc/NEWS
Modules/datetimemodule.c