summaryrefslogtreecommitdiffstats
path: root/Doc/lib/libdatetime.tex
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-01-24 22:36:34 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-01-24 22:36:34 (GMT)
commit8d81a012efa7fde5e43b8ea7275c7fc995cf74fa (patch)
tree4fad231a65954388e45221d5ca5a3013897e7efa /Doc/lib/libdatetime.tex
parentcd63e619b4703ed5701589d367cccb7357d67aa8 (diff)
downloadcpython-8d81a012efa7fde5e43b8ea7275c7fc995cf74fa.zip
cpython-8d81a012efa7fde5e43b8ea7275c7fc995cf74fa.tar.gz
cpython-8d81a012efa7fde5e43b8ea7275c7fc995cf74fa.tar.bz2
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.
Diffstat (limited to 'Doc/lib/libdatetime.tex')
-rw-r--r--Doc/lib/libdatetime.tex16
1 files changed, 16 insertions, 0 deletions
diff --git a/Doc/lib/libdatetime.tex b/Doc/lib/libdatetime.tex
index 058d6d5..693ae79 100644
--- a/Doc/lib/libdatetime.tex
+++ b/Doc/lib/libdatetime.tex
@@ -381,6 +381,14 @@ Supported operations:
comparison of date to date, where date1 is considered less than
date2 when date1 precedes date2 in time. In other words,
date1 < date2 if and only if date1.toordinal() < date2.toordinal().
+ \note{In order to stop comparison from falling back to the default
+ scheme of comparing object addresses, date comparison
+ normally raises \exception{TypeError} if the other comparand
+ isn't also a \class{date} object. However, \code{NotImplemented}
+ is returned instead if the other comparand has a
+ \method{timetuple} attribute. This hook gives other kinds of
+ date objects a chance at implementing mixed-type comparison.}
+
\item
hash, use as dict key
@@ -711,6 +719,14 @@ Supported operations:
are compared. If both comparands are aware and have different
\member{tzinfo} members, the comparands are first adjusted by
subtracting their UTC offsets (obtained from \code{self.utcoffset()}).
+ \note{In order to stop comparison from falling back to the default
+ scheme of comparing object addresses, datetime comparison
+ normally raises \exception{TypeError} if the other comparand
+ isn't also a \class{datetime} object. However,
+ \code{NotImplemented} is returned instead if the other comparand
+ has a \method{timetuple} attribute. This hook gives other
+ kinds of date objects a chance at implementing mixed-type
+ comparison.}
\item
hash, use as dict key