]> granicus.if.org Git - python/commit
Comparison for timedelta, time, date and datetime objects: __eq__ and
authorTim Peters <tim.peters@gmail.com>
Fri, 7 Feb 2003 22:50:28 +0000 (22:50 +0000)
committerTim Peters <tim.peters@gmail.com>
Fri, 7 Feb 2003 22:50:28 +0000 (22:50 +0000)
commit07534a607bd3d2fd232323811a83279acda10885
tree129fc63de44a72f412e64c591746530324261500
parent275666fd50eaf494448ba102652d4273b135a017
Comparison for timedelta, time, date and datetime objects:  __eq__ and
__ne__ no longer complain if they don't know how to compare to the other
thing.  If no meaningful way to compare is known, saying "not equal" is
sensible.  This allows things like

    if adatetime in some_sequence:
and
    somedict[adatetime] = whatever

to work as expected even if some_sequence contains non-datetime objects,
or somedict non-datetime keys, because they only call __eq__.

It still complains (raises TypeError) for mixed-type comparisons in
contexts that require a total ordering, such as list.sort(), use as a
key in a BTree-based data structure, and cmp().
Doc/lib/libdatetime.tex
Lib/test/test_datetime.py
Misc/NEWS
Modules/datetimemodule.c