[Python-checkins] [3.12] gh-107810: Improve DeprecationWarning for metaclasses with custom tp_new (GH-107834) (#107864)

Yhg1s webhook-mailer at python.org
Fri Aug 11 10:12:54 EDT 2023


https://github.com/python/cpython/commit/431ce239d2a906ec4d9a27a83549258d7cef3701
commit: 431ce239d2a906ec4d9a27a83549258d7cef3701
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Yhg1s <thomas at python.org>
date: 2023-08-11T16:12:50+02:00
summary:

[3.12] gh-107810: Improve DeprecationWarning for metaclasses with custom tp_new (GH-107834) (#107864)

gh-107810: Improve DeprecationWarning for metaclasses with custom tp_new (GH-107834)

(cherry picked from commit 16dcce21768ba381996a88ac8c255bf1490b3680)

Co-authored-by: Marc Mueller <30130371+cdce8p at users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <kirill.bast9 at mail.ru>

files:
A Misc/NEWS.d/next/C API/2023-08-10-11-12-25.gh-issue-107810.oJ40Qx.rst
M Lib/test/test_capi/test_misc.py
M Objects/typeobject.c

diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py
index cd37fc71aa966..3f2736da7d93a 100644
--- a/Lib/test/test_capi/test_misc.py
+++ b/Lib/test/test_capi/test_misc.py
@@ -740,7 +740,7 @@ class Base(metaclass=metaclass):
 
         # Class creation from C
         with warnings_helper.check_warnings(
-                ('.*custom tp_new.*in Python 3.14.*', DeprecationWarning),
+                ('.* _testcapi.Subclass .* custom tp_new.*in Python 3.14.*', DeprecationWarning),
                 ):
             sub = _testcapi.make_type_with_base(Base)
         self.assertTrue(issubclass(sub, Base))
diff --git a/Misc/NEWS.d/next/C API/2023-08-10-11-12-25.gh-issue-107810.oJ40Qx.rst b/Misc/NEWS.d/next/C API/2023-08-10-11-12-25.gh-issue-107810.oJ40Qx.rst
new file mode 100644
index 0000000000000..c8a1f6d122b61
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2023-08-10-11-12-25.gh-issue-107810.oJ40Qx.rst	
@@ -0,0 +1 @@
+Improve :exc:`DeprecationWarning` for uses of :c:type:`PyType_Spec` with metaclasses that have custom ``tp_new``.
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 40e187d4d8d22..5c71c28f75150 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -4242,9 +4242,9 @@ _PyType_FromMetaclass_impl(
         if (_allow_tp_new) {
             if (PyErr_WarnFormat(
                     PyExc_DeprecationWarning, 1,
-                    "Using PyType_Spec with metaclasses that have custom "
-                    "tp_new is deprecated and will no longer be allowed in "
-                    "Python 3.14.") < 0) {
+                    "Type %s uses PyType_Spec with a metaclass that has custom "
+                    "tp_new. This is deprecated and will no longer be allowed in "
+                    "Python 3.14.", spec->name) < 0) {
                 goto finally;
             }
         }



More information about the Python-checkins mailing list