Kaydet (Commit) 0085a240 authored tarafından Georg Brandl's avatar Georg Brandl

Closes #15973: fix a segmentation fault when comparing timezone objects.

üst fd296ff5
......@@ -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):
......
......@@ -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
......
......@@ -31,6 +31,9 @@ Library
Extension Modules
-----------------
- Issue #15973: Fix a segmentation fault when comparing datetime timezone
objects.
- Issue #15977: Fix memory leak in Modules/_ssl.c when the function
_set_npn_protocols() is called multiple times, thanks to Daniel Sommermann.
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment