summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/datetime.py2
-rw-r--r--Lib/test/datetimetester.py2
-rw-r--r--Modules/_datetimemodule.c6
3 files changed, 10 insertions, 0 deletions
diff --git a/Lib/datetime.py b/Lib/datetime.py
index a15c6b0..f506e9a 100644
--- a/Lib/datetime.py
+++ b/Lib/datetime.py
@@ -1854,6 +1854,8 @@ class timezone(tzinfo):
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
index a417170..931ef6f 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -235,6 +235,8 @@ class TestTimeZone(unittest.TestCase):
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
index 6df5c03..01c85d1 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -3215,6 +3215,12 @@ timezone_richcompare(PyDateTime_TimeZone *self,
{
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);
}