]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41025: Fix subclassing for zoneinfo.ZoneInfo (GH-20965) (GH-21876)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 14 Aug 2020 15:18:24 +0000 (08:18 -0700)
committerGitHub <noreply@github.com>
Fri, 14 Aug 2020 15:18:24 +0000 (11:18 -0400)
Prior to this change, attempting to subclass the C implementation of
zoneinfo.ZoneInfo gave the following error:

    TypeError: unbound method ZoneInfo.__init_subclass__() needs an argument

https://bugs.python.org/issue41025
(cherry picked from commit 87d8287865e5c9f137f6b5cf8c34c2c509eb5e9d)

Co-authored-by: Paul Ganssle <paul@ganssle.io>
Lib/test/test_zoneinfo/test_zoneinfo.py
Misc/NEWS.d/next/Library/2020-06-18-10-34-59.bpo-41025.elf_nz.rst [new file with mode: 0644]
Modules/_zoneinfo.c

index 1f1fa60f1ffc1fe3dadf16ec20a13e594c1fe833..85703269a1336e6005344d32c2fc58f0c9433771 100644 (file)
@@ -462,7 +462,7 @@ class CZoneInfoDatetimeSubclassTest(DatetimeSubclassMixin, CZoneInfoTest):
     pass
 
 
-class ZoneInfoTestSubclass(ZoneInfoTest):
+class ZoneInfoSubclassTest(ZoneInfoTest):
     @classmethod
     def setUpClass(cls):
         super().setUpClass()
@@ -483,7 +483,7 @@ class ZoneInfoTestSubclass(ZoneInfoTest):
         self.assertIsInstance(sub_obj, self.klass)
 
 
-class CZoneInfoTestSubclass(ZoneInfoTest):
+class CZoneInfoSubclassTest(ZoneInfoSubclassTest):
     module = c_zoneinfo
 
 
diff --git a/Misc/NEWS.d/next/Library/2020-06-18-10-34-59.bpo-41025.elf_nz.rst b/Misc/NEWS.d/next/Library/2020-06-18-10-34-59.bpo-41025.elf_nz.rst
new file mode 100644 (file)
index 0000000..21e184d
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed an issue preventing the C implementation of :class:`zoneinfo.ZoneInfo`
+from being subclassed.
index bee84cbf8f9f422f226979c5766c473bcb9e5c99..12b3969959bacfb59e9b83e354a80bd9cbf079dc 100644 (file)
@@ -2557,7 +2557,7 @@ static PyMethodDef zoneinfo_methods[] = {
     {"_unpickle", (PyCFunction)zoneinfo__unpickle, METH_VARARGS | METH_CLASS,
      PyDoc_STR("Private method used in unpickling.")},
     {"__init_subclass__", (PyCFunction)(void (*)(void))zoneinfo_init_subclass,
-     METH_VARARGS | METH_KEYWORDS,
+     METH_VARARGS | METH_KEYWORDS | METH_CLASS,
      PyDoc_STR("Function to initialize subclasses.")},
     {NULL} /* Sentinel */
 };