Skip to content

Commit 44a533f

Browse files
sobolevnZeroIntensityvstinner
authored
gh-150671: Deprecate PyAsyncGen_New, PyCoro_New, PyGen_New, PyGen_NewWithQualName functions (#150672)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent f2a0f82 commit 44a533f

6 files changed

Lines changed: 51 additions & 5 deletions

File tree

Doc/c-api/coro.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ return.
3333
with ``__name__`` and ``__qualname__`` set to *name* and *qualname*.
3434
A reference to *frame* is stolen by this function. The *frame* argument
3535
must not be ``NULL``.
36+
37+
.. deprecated-removed:: 3.16 3.18
38+
39+
This function has not been used since 3.10.
40+
It is also impossible to construct a proper *frame*
41+
object to call this function.

Doc/c-api/gen.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,25 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
3838
A reference to *frame* is stolen by this function. The argument must not be
3939
``NULL``.
4040
41+
.. deprecated-removed:: 3.16 3.18
42+
43+
This function has not been used since 3.10.
44+
It is also impossible to construct a proper *frame*
45+
object to call this function.
46+
4147
.. c:function:: PyObject* PyGen_NewWithQualName(PyFrameObject *frame, PyObject *name, PyObject *qualname)
4248
4349
Create and return a new generator object based on the *frame* object,
4450
with ``__name__`` and ``__qualname__`` set to *name* and *qualname*.
4551
A reference to *frame* is stolen by this function. The *frame* argument
4652
must not be ``NULL``.
4753
54+
.. deprecated-removed:: 3.16 3.18
55+
56+
This function has not been used since 3.10.
57+
It is also impossible to construct a proper *frame*
58+
object to call this function.
59+
4860
4961
.. c:function:: PyCodeObject* PyGen_GetCode(PyGenObject *gen)
5062
@@ -77,6 +89,12 @@ Asynchronous Generator Objects
7789
7890
.. versionadded:: 3.6
7991
92+
.. deprecated-removed:: 3.16 3.18
93+
94+
This function has not been used since 3.10.
95+
It is also impossible to construct a proper *frame*
96+
object to call this function.
97+
8098
.. c:function:: int PyAsyncGen_CheckExact(PyObject *op)
8199
82100
Return true if *op* is an asynchronous generator object, false otherwise.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Pending removal in Python 3.18
4040
* :c:func:`!_PyUnicodeWriter_PrepareKind`: (no replacement).
4141
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
4242
* :c:func:`!_Py_fopen_obj`: use :c:func:`Py_fopen`.
43+
* :c:func:`PyGen_New`: (no replacement).
44+
* :c:func:`PyGen_NewWithQualName`: (no replacement).
45+
* :c:func:`PyCoro_New`: (no replacement).
46+
* :c:func:`PyAsyncGen_New`: (no replacement).
4347

4448
The `pythoncapi-compat project
4549
<https://github.com/python/pythoncapi-compat/>`__ can be used to get

Doc/whatsnew/3.16.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,14 @@ Deprecated
275275
276276
.. include:: ../deprecations/pending-removal-in-3.17.rst
277277

278+
.. include:: ../deprecations/pending-removal-in-3.18.rst
279+
278280
.. include:: ../deprecations/pending-removal-in-3.19.rst
279281

280282
.. include:: ../deprecations/pending-removal-in-3.20.rst
281283

284+
.. include:: ../deprecations/pending-removal-in-3.21.rst
285+
282286
.. include:: ../deprecations/pending-removal-in-future.rst
283287

284288

@@ -326,9 +330,19 @@ Porting to Python 3.16
326330
Deprecated C APIs
327331
-----------------
328332

329-
* TODO
333+
* :c:func:`PyGen_New`, :c:func:`PyGen_NewWithQualName`, :c:func:`PyCoro_New`,
334+
and :c:func:`PyAsyncGen_New` are deprecated.
335+
They are scheduled for removal in 3.18.
330336

331337
.. Add C API deprecations above alphabetically, not here at the end.
332338
339+
.. include:: ../deprecations/c-api-pending-removal-in-3.18.rst
340+
341+
.. include:: ../deprecations/c-api-pending-removal-in-3.19.rst
342+
343+
.. include:: ../deprecations/c-api-pending-removal-in-3.20.rst
344+
345+
.. include:: ../deprecations/c-api-pending-removal-in-future.rst
346+
333347
Removed C APIs
334348
--------------

Include/cpython/genobject.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ PyAPI_DATA(PyTypeObject) PyGen_Type;
1616
#define PyGen_Check(op) PyObject_TypeCheck((op), &PyGen_Type)
1717
#define PyGen_CheckExact(op) Py_IS_TYPE((op), &PyGen_Type)
1818

19-
PyAPI_FUNC(PyObject *) PyGen_New(PyFrameObject *);
20-
PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(PyFrameObject *,
19+
Py_DEPRECATED(3.16) PyAPI_FUNC(PyObject *) PyGen_New(PyFrameObject *);
20+
Py_DEPRECATED(3.16) PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(PyFrameObject *,
2121
PyObject *name, PyObject *qualname);
2222
PyAPI_FUNC(PyCodeObject *) PyGen_GetCode(PyGenObject *gen);
2323

@@ -29,7 +29,7 @@ typedef struct _PyCoroObject PyCoroObject;
2929
PyAPI_DATA(PyTypeObject) PyCoro_Type;
3030

3131
#define PyCoro_CheckExact(op) Py_IS_TYPE((op), &PyCoro_Type)
32-
PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *,
32+
Py_DEPRECATED(3.16) PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *,
3333
PyObject *name, PyObject *qualname);
3434

3535

@@ -40,7 +40,7 @@ typedef struct _PyAsyncGenObject PyAsyncGenObject;
4040
PyAPI_DATA(PyTypeObject) PyAsyncGen_Type;
4141
PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type;
4242

43-
PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
43+
Py_DEPRECATED(3.16) PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
4444
PyObject *name, PyObject *qualname);
4545

4646
#define PyAsyncGen_CheckExact(op) Py_IS_TYPE((op), &PyAsyncGen_Type)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Deprecate these C-API functions: :c:func:`PyGen_New`,
2+
:c:func:`PyGen_NewWithQualName`, :c:func:`PyCoro_New`, and
3+
:c:func:`PyAsyncGen_New`.
4+
Schedule them for removal in 3.18

0 commit comments

Comments
 (0)