Skip to content

Commit 87d8287

Browse files
authored
bpo-41025: Fix subclassing for zoneinfo.ZoneInfo (GH-20965)
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
1 parent e55de68 commit 87d8287

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

Lib/test/test_zoneinfo/test_zoneinfo.py

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

465465

466-
class ZoneInfoTestSubclass(ZoneInfoTest):
466+
class ZoneInfoSubclassTest(ZoneInfoTest):
467467
@classmethod
468468
def setUpClass(cls):
469469
super().setUpClass()
@@ -484,7 +484,7 @@ def test_subclass_own_cache(self):
484484
self.assertIsInstance(sub_obj, self.klass)
485485

486486

487-
class CZoneInfoTestSubclass(ZoneInfoTest):
487+
class CZoneInfoSubclassTest(ZoneInfoSubclassTest):
488488
module = c_zoneinfo
489489

490490

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)