[Python-checkins] python/dist/src/Modules datetimemodule.c, 1.74, 1.75

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Thu Sep 16 03:30:52 CEST 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3145/Modules

Modified Files:
	datetimemodule.c 
Log Message:
SF bug #1028306:  date-datetime comparison

Treat comparing a date to a datetime like a mixed-type comparison.


Index: datetimemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/datetimemodule.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- datetimemodule.c	20 Jun 2004 22:41:32 -0000	1.74
+++ datetimemodule.c	16 Sep 2004 01:30:50 -0000	1.75
@@ -4075,7 +4075,17 @@
 	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;



More information about the Python-checkins mailing list