]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-142217: Deprecate the private _Py_Identifier C API (#142221)
authorVictor Stinner <vstinner@python.org>
Fri, 12 Dec 2025 13:10:25 +0000 (14:10 +0100)
committerGitHub <noreply@github.com>
Fri, 12 Dec 2025 13:10:25 +0000 (14:10 +0100)
Deprecate functions:

* _PyObject_CallMethodId()
* _PyObject_GetAttrId()
* _PyUnicode_FromId()

Doc/deprecations/c-api-pending-removal-in-3.20.rst
Doc/whatsnew/3.15.rst
Include/cpython/abstract.h
Include/cpython/object.h
Include/cpython/unicodeobject.h
Misc/NEWS.d/next/C_API/2025-12-03-14-41-07.gh-issue-141049.VuAUe2.rst [new file with mode: 0644]
Objects/call.c
Objects/object.c

index 18623b19a2ab8da7988e62b012d52fddc1e5d8f1..a813cb21dd4dbffb2a31ad1d5b11a92bba89accd 100644 (file)
@@ -1,6 +1,13 @@
 Pending removal in Python 3.20
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
+* :c:func:`!_PyObject_CallMethodId`, :c:func:`!_PyObject_GetAttrId` and
+  :c:func:`!_PyUnicode_FromId` are deprecated since 3.15 and will be removed in
+  3.20. Instead, use :c:func:`PyUnicode_FromString()` and cache the result in
+  the module state, then call :c:func:`PyObject_CallMethod` or
+  :c:func:`PyObject_GetAttr`.
+  (Contributed by Victor Stinner in :gh:`141049`.)
+
 * The ``cval`` field in :c:type:`PyComplexObject` (:gh:`128813`).
   Use :c:func:`PyComplex_AsCComplex` and :c:func:`PyComplex_FromCComplex`
   to convert a Python complex number to/from the C :c:type:`Py_complex`
index 9d4686f982a99af5dc61bd7f7d9211f54ec4bbc5..1d8b838cd2e7f07907a0938ce55f4eb3cc6537f2 100644 (file)
@@ -1210,6 +1210,13 @@ Deprecated C APIs
   use the :c:type:`PyBytesWriter` API instead.
   (Contributed by Victor Stinner in :gh:`129813`.)
 
+* :c:func:`!_PyObject_CallMethodId`, :c:func:`!_PyObject_GetAttrId` and
+  :c:func:`!_PyUnicode_FromId` are deprecated since 3.15 and will be removed in
+  3.20. Instead, use :c:func:`PyUnicode_FromString()` and cache the result in
+  the module state, then call :c:func:`PyObject_CallMethod` or
+  :c:func:`PyObject_GetAttr`.
+  (Contributed by Victor Stinner in :gh:`141049`.)
+
 * Deprecate :c:member:`~PyComplexObject.cval` field of the
   :c:type:`PyComplexObject` type.
   Use :c:func:`PyComplex_AsCComplex` and :c:func:`PyComplex_FromCComplex`
index ffd19ccd3500fac847eb379eaed953aa67d12bec..7490ece52e5220e82acc8bc48ed519a05f59d7c8 100644 (file)
@@ -6,7 +6,7 @@
 
 /* Like PyObject_CallMethod(), but expect a _Py_Identifier*
    as the method name. */
-PyAPI_FUNC(PyObject*) _PyObject_CallMethodId(
+Py_DEPRECATED(3.15) PyAPI_FUNC(PyObject*) _PyObject_CallMethodId(
     PyObject *obj,
     _Py_Identifier *name,
     const char *format, ...);
index 8693390aeda624e934beeca05b00861569194272..85d5edd62e3a72e0239ff968c9018e7ad720bd87 100644 (file)
@@ -300,7 +300,7 @@ PyAPI_FUNC(void) PyUnstable_Object_Dump(PyObject *);
 // Alias for backward compatibility
 #define _PyObject_Dump PyUnstable_Object_Dump
 
-PyAPI_FUNC(PyObject*) _PyObject_GetAttrId(PyObject *, _Py_Identifier *);
+Py_DEPRECATED(3.15) PyAPI_FUNC(PyObject*) _PyObject_GetAttrId(PyObject *, _Py_Identifier *);
 
 PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
 PyAPI_FUNC(void) PyObject_CallFinalizer(PyObject *);
index 2853d24c34b66ecd54bb2e38e027cd841c6b7bb9..631a6570658410891024204cc68db33f62be7cb7 100644 (file)
@@ -778,4 +778,4 @@ static inline int Py_UNICODE_ISALNUM(Py_UCS4 ch) {
 
 // Return an interned Unicode object for an Identifier; may fail if there is no
 // memory.
-PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);
+Py_DEPRECATED(3.15) PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);
diff --git a/Misc/NEWS.d/next/C_API/2025-12-03-14-41-07.gh-issue-141049.VuAUe2.rst b/Misc/NEWS.d/next/C_API/2025-12-03-14-41-07.gh-issue-141049.VuAUe2.rst
new file mode 100644 (file)
index 0000000..b0fcd24
--- /dev/null
@@ -0,0 +1,5 @@
+:c:func:`!_PyObject_CallMethodId`, :c:func:`!_PyObject_GetAttrId` and
+:c:func:`!_PyUnicode_FromId` are deprecated since 3.15 and will be removed in
+3.20. Instead, use :c:func:`PyUnicode_FromString()` and cache the result in
+the module state, then call :c:func:`PyObject_CallMethod` or
+:c:func:`PyObject_GetAttr`. Patch by Victor Stinner.
index c69015abfb3ed5e5a5a426cd80e0a77c67811f6c..41d075caf11ce6cb231d72477b9e0e9d8f197297 100644 (file)
@@ -708,7 +708,10 @@ _PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name,
         return null_error(tstate);
     }
 
+_Py_COMP_DIAG_PUSH
+_Py_COMP_DIAG_IGNORE_DEPR_DECLS
     PyObject *callable = _PyObject_GetAttrId(obj, name);
+_Py_COMP_DIAG_POP
     if (callable == NULL) {
         return NULL;
     }
index 36a37bb0bbea4dfb59a505bd4b1bef2c42622542..4fc692bb02940e4bafb2812f81bfafb8d8d8416b 100644 (file)
@@ -1263,7 +1263,10 @@ PyObject *
 _PyObject_GetAttrId(PyObject *v, _Py_Identifier *name)
 {
     PyObject *result;
+_Py_COMP_DIAG_PUSH
+_Py_COMP_DIAG_IGNORE_DEPR_DECLS
     PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
+_Py_COMP_DIAG_POP
     if (!oname)
         return NULL;
     result = PyObject_GetAttr(v, oname);