diff -r 11a6ee1fd7e4 Lib/test/test_datetime.py --- a/Lib/test/test_datetime.py Sat Mar 21 00:16:14 2009 +0100 +++ b/Lib/test/test_datetime.py Mon Mar 23 14:12:11 2009 -0500 @@ -3327,12 +3327,7 @@ self.assertRaises(TypeError, lambda: as_date >= as_datetime) self.assertRaises(TypeError, lambda: as_datetime >= as_date) - # Neverthelss, comparison should work with the base-class (date) - # projection if use of a date method is forced. - self.assert_(as_date.__eq__(as_datetime)) - different_day = (as_date.day + 1) % 20 + 1 - self.assert_(not as_date.__eq__(as_datetime.replace(day= - different_day))) + # [removed two tests here due to fix for issue 5516] # And date should compare with other subclasses of date. If a # subclass wants to stop this, it's up to the subclass to do so. @@ -3346,6 +3341,16 @@ self.assertEqual(as_datetime, datetime_sc) self.assertEqual(datetime_sc, as_datetime) + # subclasses should have the same __eq__ behavior as date and datetime + class D(date): + pass + class DT(datetime): + pass + d = D(2008, 1, 1) + dt = DT(2008, 1, 1) + self.assertNotEqual(d, dt) + self.assertNotEqual(dt, d) + def test_main(): test_support.run_unittest(__name__) diff -r 11a6ee1fd7e4 Modules/datetimemodule.c --- a/Modules/datetimemodule.c Sat Mar 21 00:16:14 2009 +0100 +++ b/Modules/datetimemodule.c Mon Mar 23 14:12:11 2009 -0500 @@ -2575,10 +2575,15 @@ { int diff = 42; /* nonsense */ - if (PyDate_Check(other)) - diff = memcmp(self->data, ((PyDateTime_Date *)other)->data, - _PyDateTime_DATE_DATASIZE); - + if (PyDate_Check(other)) { + if (PyDateTime_Check(other)) + diff = 1; + else + diff = memcmp(self->data, + ((PyDateTime_Date *)other)->data, + _PyDateTime_DATE_DATASIZE); + + } else if (PyObject_HasAttrString(other, "timetuple")) { /* A hook for other kinds of date objects. */ Py_INCREF(Py_NotImplemented);