]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-107810: Improve DeprecationWarning for metaclasses with custom tp_new (GH-107834)
authorMarc Mueller <30130371+cdce8p@users.noreply.github.com>
Thu, 10 Aug 2023 15:55:47 +0000 (17:55 +0200)
committerGitHub <noreply@github.com>
Thu, 10 Aug 2023 15:55:47 +0000 (15:55 +0000)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Lib/test/test_capi/test_misc.py
Misc/NEWS.d/next/C API/2023-08-10-11-12-25.gh-issue-107810.oJ40Qx.rst [new file with mode: 0644]
Objects/typeobject.c

index 001d37de8e0eb38b62cde8366a3694b491e389ca..c81212202d9ef2aa7b05ecfe63184d1c1b9115da 100644 (file)
@@ -611,7 +611,7 @@ class CAPITest(unittest.TestCase):
 
         # 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 (file)
index 0000000..c8a1f6d
--- /dev/null
@@ -0,0 +1 @@
+Improve :exc:`DeprecationWarning` for uses of :c:type:`PyType_Spec` with metaclasses that have custom ``tp_new``.
index 71e96f5af4e4199205a17def21c5cd6c571252f1..aca14e79a1997940dbd71bed95587177da8583bd 100644 (file)
@@ -4264,9 +4264,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;
             }
         }