summaryrefslogtreecommitdiffstats
path: root/Modules/datetimemodule.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2004-09-16 01:30:50 (GMT)
committerTim Peters <tim.peters@gmail.com>2004-09-16 01:30:50 (GMT)
commit528ca53b7455b3307cb0e3f097ae951191521ba8 (patch)
treebad5eb084b5b64040699077cae94427ae750672f /Modules/datetimemodule.c
parentc74298a72b16d2ecca144df014014796f025ea08 (diff)
downloadcpython-528ca53b7455b3307cb0e3f097ae951191521ba8.zip
cpython-528ca53b7455b3307cb0e3f097ae951191521ba8.tar.gz
cpython-528ca53b7455b3307cb0e3f097ae951191521ba8.tar.bz2
SF bug #1028306: date-datetime comparison
Treat comparing a date to a datetime like a mixed-type comparison.
Diffstat (limited to 'Modules/datetimemodule.c')
-rw-r--r--Modules/datetimemodule.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index ee7387c..6312e21 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -4075,7 +4075,17 @@ datetime_richcompare(PyDateTime_DateTime *self, PyObject *other, int op)
int offset1, offset2;
if (! PyDateTime_Check(other)) {
- if (PyObject_HasAttrString(other, "timetuple")) {
+ /* If other has a "timetuple" attr, that's an advertised
+ * hook for other classes to ask to get comparison control.
+ * However, date instances have a timetuple attr, and we
+ * don't want to allow that comparison. Because datetime
+ * is a subclass of date, when mixing date and datetime
+ * in a comparison, Python gives datetime the first shot
+ * (it's the more specific subtype). So we can stop that
+ * combination here reliably.
+ */
+ if (PyObject_HasAttrString(other, "timetuple") &&
+ ! PyDate_Check(other)) {
/* A hook for other kinds of datetime objects. */
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;