From c689f7cc86579f1a5b4d33c8e18019ba08e4591a Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Wed, 29 Nov 2023 12:47:19 +0100 Subject: [PATCH] gh-112451: Make C-extension datetime.timezone acceptable as a base class. --- Lib/test/test_types.py | 5 +++++ Modules/_datetimemodule.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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/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 */