Commit 4be11c00 authored by Pablo Galindo's avatar Pablo Galindo Committed by Miss Islington (bot)

bpo-37915: Fix comparison between tzinfo objects and timezone objects (GH-15390)



https://bugs.python.org/issue37915



Automerge-Triggered-By: @pablogsal
parent 8889627b
...@@ -413,6 +413,11 @@ class TestTimeZone(unittest.TestCase): ...@@ -413,6 +413,11 @@ class TestTimeZone(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
timezone(delta) timezone(delta)
def test_comparison_with_tzinfo(self):
# Constructing tzinfo objects directly should not be done by users
# and serves only to check the bug described in bpo-37915
self.assertNotEqual(timezone.utc, tzinfo())
self.assertNotEqual(timezone(timedelta(hours=1)), tzinfo())
############################################################################# #############################################################################
# Base class for testing a particular aspect of timedelta, time, date and # Base class for testing a particular aspect of timedelta, time, date and
......
Fix a segmentation fault that appeared when comparing instances of
``datetime.timezone`` and ``datetime.tzinfo`` objects. Patch by Pablo
Galindo.
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType) #define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType)
#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TZInfoType) #define PyTZInfo_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TZInfoType)
#define PyTimezone_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeZoneType)
/*[clinic input] /*[clinic input]
module datetime module datetime
...@@ -3745,7 +3746,7 @@ timezone_richcompare(PyDateTime_TimeZone *self, ...@@ -3745,7 +3746,7 @@ timezone_richcompare(PyDateTime_TimeZone *self,
{ {
if (op != Py_EQ && op != Py_NE) if (op != Py_EQ && op != Py_NE)
Py_RETURN_NOTIMPLEMENTED; Py_RETURN_NOTIMPLEMENTED;
if (!PyTZInfo_Check(other)) { if (!PyTimezone_Check(other)) {
Py_RETURN_NOTIMPLEMENTED; Py_RETURN_NOTIMPLEMENTED;
} }
return delta_richcompare(self->offset, other->offset, op); 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