[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 16dcce2176)

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
This commit is contained in:
Miss Islington (bot) 2023-08-11 07:12:50 -07:00 committed by GitHub
parent 585b4cc3bd
commit 431ce239d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

View file

@ -740,7 +740,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))

View file

@ -0,0 +1 @@
Improve :exc:`DeprecationWarning` for uses of :c:type:`PyType_Spec` with metaclasses that have custom ``tp_new``.

View file

@ -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;
}
}