summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2012-09-20 20:49:58 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2012-09-20 20:49:58 (GMT)
commit6f543a307332b6034c22da2e979233b3b05b7dff (patch)
tree4a0f0a25dcb43b064d1521cd7a2afd0989617ddb
parentc286e58044839bd8d946b12fee454ae861e6cdbc (diff)
parent3ec153681e4e5553fc6882699beb5af6d45c75e6 (diff)
downloadcpython-6f543a307332b6034c22da2e979233b3b05b7dff.zip
cpython-6f543a307332b6034c22da2e979233b3b05b7dff.tar.gz
cpython-6f543a307332b6034c22da2e979233b3b05b7dff.tar.bz2
merge
-rw-r--r--Lib/datetime.py2
-rw-r--r--Lib/test/datetimetester.py2
-rw-r--r--Modules/_datetimemodule.c10
3 files changed, 11 insertions, 3 deletions
diff --git a/Lib/datetime.py b/Lib/datetime.py
index 65f95d2..bf23e50 100644
--- a/Lib/datetime.py
+++ b/Lib/datetime.py
@@ -1821,6 +1821,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 3fd6799..bb18630 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 8f571ad..444cc00 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -3243,9 +3243,13 @@ static PyObject *
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);
}