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
This commit is contained in:
Paul Ganssle 2020-08-13 22:38:30 -04:00 committed by GitHub
parent e55de68be3
commit 87d8287865
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

View File

@ -463,7 +463,7 @@ class CZoneInfoDatetimeSubclassTest(DatetimeSubclassMixin, CZoneInfoTest):
pass pass
class ZoneInfoTestSubclass(ZoneInfoTest): class ZoneInfoSubclassTest(ZoneInfoTest):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
@ -484,7 +484,7 @@ class ZoneInfoTestSubclass(ZoneInfoTest):
self.assertIsInstance(sub_obj, self.klass) self.assertIsInstance(sub_obj, self.klass)
class CZoneInfoTestSubclass(ZoneInfoTest): class CZoneInfoSubclassTest(ZoneInfoSubclassTest):
module = c_zoneinfo module = c_zoneinfo

View File

@ -0,0 +1,2 @@
Fixed an issue preventing the C implementation of :class:`zoneinfo.ZoneInfo`
from being subclassed.

View File

@ -2557,7 +2557,7 @@ static PyMethodDef zoneinfo_methods[] = {
{"_unpickle", (PyCFunction)zoneinfo__unpickle, METH_VARARGS | METH_CLASS, {"_unpickle", (PyCFunction)zoneinfo__unpickle, METH_VARARGS | METH_CLASS,
PyDoc_STR("Private method used in unpickling.")}, PyDoc_STR("Private method used in unpickling.")},
{"__init_subclass__", (PyCFunction)(void (*)(void))zoneinfo_init_subclass, {"__init_subclass__", (PyCFunction)(void (*)(void))zoneinfo_init_subclass,
METH_VARARGS | METH_KEYWORDS, METH_VARARGS | METH_KEYWORDS | METH_CLASS,
PyDoc_STR("Function to initialize subclasses.")}, PyDoc_STR("Function to initialize subclasses.")},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };