Skip to content

Commit 7aa353c

Browse files
authored
gh-142217: Deprecate the private _Py_Identifier C API (#142221)
Deprecate functions: * _PyObject_CallMethodId() * _PyObject_GetAttrId() * _PyUnicode_FromId()
1 parent be5e0dc commit 7aa353c

File tree

8 files changed

+28
-3
lines changed

8 files changed

+28
-3
lines changed

Doc/deprecations/c-api-pending-removal-in-3.20.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Pending removal in Python 3.20
22
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33

4+
* :c:func:`!_PyObject_CallMethodId`, :c:func:`!_PyObject_GetAttrId` and
5+
:c:func:`!_PyUnicode_FromId` are deprecated since 3.15 and will be removed in
6+
3.20. Instead, use :c:func:`PyUnicode_FromString()` and cache the result in
7+
the module state, then call :c:func:`PyObject_CallMethod` or
8+
:c:func:`PyObject_GetAttr`.
9+
(Contributed by Victor Stinner in :gh:`141049`.)
10+
411
* The ``cval`` field in :c:type:`PyComplexObject` (:gh:`128813`).
512
Use :c:func:`PyComplex_AsCComplex` and :c:func:`PyComplex_FromCComplex`
613
to convert a Python complex number to/from the C :c:type:`Py_complex`

Doc/whatsnew/3.15.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,13 @@ Deprecated C APIs
12101210
use the :c:type:`PyBytesWriter` API instead.
12111211
(Contributed by Victor Stinner in :gh:`129813`.)
12121212

1213+
* :c:func:`!_PyObject_CallMethodId`, :c:func:`!_PyObject_GetAttrId` and
1214+
:c:func:`!_PyUnicode_FromId` are deprecated since 3.15 and will be removed in
1215+
3.20. Instead, use :c:func:`PyUnicode_FromString()` and cache the result in
1216+
the module state, then call :c:func:`PyObject_CallMethod` or
1217+
:c:func:`PyObject_GetAttr`.
1218+
(Contributed by Victor Stinner in :gh:`141049`.)
1219+
12131220
* Deprecate :c:member:`~PyComplexObject.cval` field of the
12141221
:c:type:`PyComplexObject` type.
12151222
Use :c:func:`PyComplex_AsCComplex` and :c:func:`PyComplex_FromCComplex`

Include/cpython/abstract.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/* Like PyObject_CallMethod(), but expect a _Py_Identifier*
88
as the method name. */
9-
PyAPI_FUNC(PyObject*) _PyObject_CallMethodId(
9+
Py_DEPRECATED(3.15) PyAPI_FUNC(PyObject*) _PyObject_CallMethodId(
1010
PyObject *obj,
1111
_Py_Identifier *name,
1212
const char *format, ...);

Include/cpython/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ PyAPI_FUNC(void) PyUnstable_Object_Dump(PyObject *);
300300
// Alias for backward compatibility
301301
#define _PyObject_Dump PyUnstable_Object_Dump
302302

303-
PyAPI_FUNC(PyObject*) _PyObject_GetAttrId(PyObject *, _Py_Identifier *);
303+
Py_DEPRECATED(3.15) PyAPI_FUNC(PyObject*) _PyObject_GetAttrId(PyObject *, _Py_Identifier *);
304304

305305
PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
306306
PyAPI_FUNC(void) PyObject_CallFinalizer(PyObject *);

Include/cpython/unicodeobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,4 +778,4 @@ static inline int Py_UNICODE_ISALNUM(Py_UCS4 ch) {
778778

779779
// Return an interned Unicode object for an Identifier; may fail if there is no
780780
// memory.
781-
PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);
781+
Py_DEPRECATED(3.15) PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:c:func:`!_PyObject_CallMethodId`, :c:func:`!_PyObject_GetAttrId` and
2+
:c:func:`!_PyUnicode_FromId` are deprecated since 3.15 and will be removed in
3+
3.20. Instead, use :c:func:`PyUnicode_FromString()` and cache the result in
4+
the module state, then call :c:func:`PyObject_CallMethod` or
5+
:c:func:`PyObject_GetAttr`. Patch by Victor Stinner.

Objects/call.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,10 @@ _PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name,
708708
return null_error(tstate);
709709
}
710710

711+
_Py_COMP_DIAG_PUSH
712+
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
711713
PyObject *callable = _PyObject_GetAttrId(obj, name);
714+
_Py_COMP_DIAG_POP
712715
if (callable == NULL) {
713716
return NULL;
714717
}

Objects/object.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,10 @@ PyObject *
12631263
_PyObject_GetAttrId(PyObject *v, _Py_Identifier *name)
12641264
{
12651265
PyObject *result;
1266+
_Py_COMP_DIAG_PUSH
1267+
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
12661268
PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
1269+
_Py_COMP_DIAG_POP
12671270
if (!oname)
12681271
return NULL;
12691272
result = PyObject_GetAttr(v, oname);

0 commit comments

Comments
 (0)