mirror of
https://github.com/python/cpython.git
synced 2025-11-02 11:08:57 +00:00
Issue #15973: Fixed segmentation fault on timezone comparison to other types.
This commit is contained in:
parent
4e12ad19c9
commit
3ec153681e
3 changed files with 11 additions and 3 deletions
|
|
@ -1821,6 +1821,8 @@ class timezone(tzinfo):
|
||||||
return (self._offset, self._name)
|
return (self._offset, self._name)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
if type(other) != timezone:
|
||||||
|
return False
|
||||||
return self._offset == other._offset
|
return self._offset == other._offset
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
|
|
|
||||||
|
|
@ -235,6 +235,8 @@ class TestTimeZone(unittest.TestCase):
|
||||||
self.assertEqual(timezone(-5 * HOUR), timezone(-5 * HOUR, 'EST'))
|
self.assertEqual(timezone(-5 * HOUR), timezone(-5 * HOUR, 'EST'))
|
||||||
with self.assertRaises(TypeError): timezone(ZERO) < timezone(ZERO)
|
with self.assertRaises(TypeError): timezone(ZERO) < timezone(ZERO)
|
||||||
self.assertIn(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):
|
def test_aware_datetime(self):
|
||||||
# test that timezone instances can be used by datetime
|
# test that timezone instances can be used by datetime
|
||||||
|
|
|
||||||
|
|
@ -3243,9 +3243,13 @@ static PyObject *
|
||||||
timezone_richcompare(PyDateTime_TimeZone *self,
|
timezone_richcompare(PyDateTime_TimeZone *self,
|
||||||
PyDateTime_TimeZone *other, int op)
|
PyDateTime_TimeZone *other, int op)
|
||||||
{
|
{
|
||||||
if (op != Py_EQ && op != Py_NE) {
|
if (op != Py_EQ && op != Py_NE)
|
||||||
Py_INCREF(Py_NotImplemented);
|
Py_RETURN_NOTIMPLEMENTED;
|
||||||
return Py_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);
|
return delta_richcompare(self->offset, other->offset, op);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue