From 6d9462686124d0310777c5e9056b40c864a368d7 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 25 Sep 2024 13:37:19 -0700 Subject: [PATCH 1/2] gh-124520: What's New for ctypes metaclass __new__/__init__ change --- Doc/whatsnew/3.13.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 45817799b542bc..d0485fa34d7cb2 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -824,6 +824,19 @@ copy (Contributed by Serhiy Storchaka in :gh:`108751`.) +ctypes +------ + +* As a consequence of necessary internal refactoring, initialization of + internal metaclasses now happens in ``__init__`` rather + than in ``__new__``. This affects projects that subclass these internal + metaclasses to provide custom initialization. + Generally, logic that was done in ``__new__`` after calling + ``super().__new__`` should be moved to ``__init__``. + See :gh:`124520` for discussion and links to changes in some affected + projects. + + dbm --- From b84f740b6070d4027be5f87de7f09741e7ad3182 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 25 Sep 2024 15:58:36 -0700 Subject: [PATCH 2/2] Call the metaclass, not just __new__ --- Doc/whatsnew/3.13.rst | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index d0485fa34d7cb2..52fe749697cfa4 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -831,8 +831,13 @@ ctypes internal metaclasses now happens in ``__init__`` rather than in ``__new__``. This affects projects that subclass these internal metaclasses to provide custom initialization. - Generally, logic that was done in ``__new__`` after calling - ``super().__new__`` should be moved to ``__init__``. + Generally: + + - Custom logic that was done in ``__new__`` after calling ``super().__new__`` + should be moved to ``__init__``. + - To create a class, call the metaclass, not only the metaclass's + ``__new__`` method. + See :gh:`124520` for discussion and links to changes in some affected projects.