]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.7] bpo-37915: Fix comparison between tzinfo objects and timezone objects (GH-15390...
authorPablo Galindo <Pablogsal@gmail.com>
Fri, 23 Aug 2019 10:12:31 +0000 (11:12 +0100)
committerGitHub <noreply@github.com>
Fri, 23 Aug 2019 10:12:31 +0000 (11:12 +0100)
https://bugs.python.org/issue37915

Automerge-Triggered-By: @pablogsal.
(cherry picked from commit 4be11c009abe88175fa164b45e4838e7267dfa97)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Lib/test/datetimetester.py
Misc/NEWS.d/next/Library/2019-08-22-16-13-27.bpo-37915.xyoZI5.rst [new file with mode: 0644]
Modules/_datetimemodule.c

index 025e71de78727f1aab2a2e6c7481fb8500d256ae..0c621f0f47c7f2d6a97c19dc20661cb1d9ecd156 100644 (file)
@@ -413,6 +413,11 @@ class TestTimeZone(unittest.TestCase):
                 with self.assertRaises(ValueError):
                     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
diff --git a/Misc/NEWS.d/next/Library/2019-08-22-16-13-27.bpo-37915.xyoZI5.rst b/Misc/NEWS.d/next/Library/2019-08-22-16-13-27.bpo-37915.xyoZI5.rst
new file mode 100644 (file)
index 0000000..1dc9ea4
--- /dev/null
@@ -0,0 +1,3 @@
+Fix a segmentation fault that appeared when comparing instances of
+``datetime.timezone`` and ``datetime.tzinfo`` objects. Patch by Pablo
+Galindo.
index 655be364d9cbec5f99e7cbfd6b2f7eb0f07ffcad..6bed29ee5cf3c669d1e7ea1a2e81ffc4c6894050 100644 (file)
@@ -20,6 +20,8 @@
 #include "datetime.h"
 #undef Py_BUILD_CORE
 
+#define PyTimezone_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeZoneType)
+
 /*[clinic input]
 module datetime
 class datetime.datetime "PyDateTime_DateTime *" "&PyDateTime_DateTimeType"
@@ -3648,7 +3650,7 @@ timezone_richcompare(PyDateTime_TimeZone *self,
 {
     if (op != Py_EQ && op != Py_NE)
         Py_RETURN_NOTIMPLEMENTED;
-    if (!PyTZInfo_Check(other)) {
+    if (!PyTimezone_Check(other)) {
         Py_RETURN_NOTIMPLEMENTED;
     }
     return delta_richcompare(self->offset, other->offset, op);