diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index da32c4ea6477ced..e92fd397d845f8a 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -640,6 +640,11 @@ def test_traceback_and_frame_types(self): def test_capsule_type(self): self.assertIsInstance(_datetime.datetime_CAPI, types.CapsuleType) + def test_timezone_base_type(self): + class MyTimezone(_datetime.timezone): + pass + + self.assertIs(issubclass(MyTimezone, _datetime.timezone), True) class UnionTests(unittest.TestCase): diff --git a/Misc/NEWS.d/next/Library/2023-11-29-12-55-55.gh-issue-112451.KFFlYs.rst b/Misc/NEWS.d/next/Library/2023-11-29-12-55-55.gh-issue-112451.KFFlYs.rst new file mode 100644 index 000000000000000..c55d4f66fe415c1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-11-29-12-55-55.gh-issue-112451.KFFlYs.rst @@ -0,0 +1 @@ +Make C-extension ``datetime.timezone`` acceptable as a base class. diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index cb5403e8461ff0e..38802f806d3537f 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -4107,7 +4107,7 @@ static PyTypeObject PyDateTime_TimeZoneType = { 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ timezone_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */