Skip to content

Commit 33d3c64

Browse files
bpo-41025: Fix subclassing for zoneinfo.ZoneInfo (GH-20965) (GH-21876)
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 87d8287) Co-authored-by: Paul Ganssle <paul@ganssle.io>
1 parent 7c28841 commit 33d3c64

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

Lib/test/test_zoneinfo/test_zoneinfo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ class CZoneInfoDatetimeSubclassTest(DatetimeSubclassMixin, CZoneInfoTest):
462462
pass
463463

464464

465-
class ZoneInfoTestSubclass(ZoneInfoTest):
465+
class ZoneInfoSubclassTest(ZoneInfoTest):
466466
@classmethod
467467
def setUpClass(cls):
468468
super().setUpClass()
@@ -483,7 +483,7 @@ def test_subclass_own_cache(self):
483483
self.assertIsInstance(sub_obj, self.klass)
484484

485485

486-
class CZoneInfoTestSubclass(ZoneInfoTest):
486+
class CZoneInfoSubclassTest(ZoneInfoSubclassTest):
487487
module = c_zoneinfo
488488

489489

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed an issue preventing the C implementation of :class:`zoneinfo.ZoneInfo`
2+
from being subclassed.

Modules/_zoneinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2557,7 +2557,7 @@ static PyMethodDef zoneinfo_methods[] = {
25572557
{"_unpickle", (PyCFunction)zoneinfo__unpickle, METH_VARARGS | METH_CLASS,
25582558
PyDoc_STR("Private method used in unpickling.")},
25592559
{"__init_subclass__", (PyCFunction)(void (*)(void))zoneinfo_init_subclass,
2560-
METH_VARARGS | METH_KEYWORDS,
2560+
METH_VARARGS | METH_KEYWORDS | METH_CLASS,
25612561
PyDoc_STR("Function to initialize subclasses.")},
25622562
{NULL} /* Sentinel */
25632563
};

0 commit comments

Comments
 (0)