[Python-checkins] cpython (merge 3.2 -> 3.2): merge

alexander.belopolsky python-checkins at python.org
Thu Sep 20 22:50:25 CEST 2012


http://hg.python.org/cpython/rev/c99cf18b2272
changeset:   79074:c99cf18b2272
branch:      3.2
parent:      79069:5ed83105731d
parent:      79071:9fba12ceb2fd
user:        Alexander Belopolsky <alexander.belopolsky at gmail.com>
date:        Thu Sep 20 16:49:58 2012 -0400
summary:
  merge

files:
  Lib/datetime.py            |   2 ++
  Lib/test/datetimetester.py |   2 ++
  Modules/_datetimemodule.c  |  10 +++++++---
  3 files changed, 11 insertions(+), 3 deletions(-)


diff --git a/Lib/datetime.py b/Lib/datetime.py
--- a/Lib/datetime.py
+++ b/Lib/datetime.py
@@ -1821,6 +1821,8 @@
         return (self._offset, self._name)
 
     def __eq__(self, other):
+        if type(other) != timezone:
+            return False
         return self._offset == other._offset
 
     def __hash__(self):
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -235,6 +235,8 @@
         self.assertEqual(timezone(-5 * HOUR), timezone(-5 * HOUR, 'EST'))
         with self.assertRaises(TypeError): timezone(ZERO) < timezone(ZERO)
         self.assertIn(timezone(ZERO), {timezone(ZERO)})
+        self.assertTrue(timezone(ZERO) != None)
+        self.assertFalse(timezone(ZERO) ==  None)
 
     def test_aware_datetime(self):
         # test that timezone instances can be used by datetime
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -3243,9 +3243,13 @@
 timezone_richcompare(PyDateTime_TimeZone *self,
                      PyDateTime_TimeZone *other, int op)
 {
-    if (op != Py_EQ && op != Py_NE) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+    if (op != Py_EQ && op != Py_NE)
+        Py_RETURN_NOTIMPLEMENTED;
+    if (Py_TYPE(other) != &PyDateTime_TimeZoneType) {
+	if (op == Py_EQ)
+	    Py_RETURN_FALSE;
+	else
+	    Py_RETURN_TRUE;
     }
     return delta_richcompare(self->offset, other->offset, op);
 }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list