Skip to content

Commit

Permalink
bpo-41025: Fix subclassing for zoneinfo.ZoneInfo (pythonGH-20965)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pganssle authored Aug 14, 2020
1 parent e55de68 commit 87d8287
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Lib/test/test_zoneinfo/test_zoneinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ class CZoneInfoDatetimeSubclassTest(DatetimeSubclassMixin, CZoneInfoTest):
pass


class ZoneInfoTestSubclass(ZoneInfoTest):
class ZoneInfoSubclassTest(ZoneInfoTest):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand All @@ -484,7 +484,7 @@ def test_subclass_own_cache(self):
self.assertIsInstance(sub_obj, self.klass)


class CZoneInfoTestSubclass(ZoneInfoTest):
class CZoneInfoSubclassTest(ZoneInfoSubclassTest):
module = c_zoneinfo


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed an issue preventing the C implementation of :class:`zoneinfo.ZoneInfo`
from being subclassed.
2 changes: 1 addition & 1 deletion Modules/_zoneinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};
Expand Down

0 comments on commit 87d8287

Please sign in to comment.