Skip to content

Request PEP 387 exception to remove 4 functions broken since Python 3.11: Py_GenNew() #156

Description

@vstinner

Hi,

I tried to debug a reference leak in PyGen_New() but I failed to write an unit test to trigger the faulty code path: python/cpython#99485 When I looked deeper, in fact PyAsyncGen_New(), PyCoro_New(), PyGen_New() and PyGen_NewWithQualName() functions are broken since Python 3.11. It's no longer possible to call them.

In Python 3.10, Python calls directly these functions. But in Python 3.11, a new internal function is called instead and the public functions were left unchanged. Problem: it's not possible to create a frame in a state which is accepted by PyGen_New().

I checked the PyPI top 5000 projects and no projects call these functions. I understand that Python itself was the only consumer of these functions.

The way to create coroutines and generators changed in Python 3.11: they are now created with no frame but from a function instead. The old API (create from a frame) is no longer usable, it no longer makes sense.

I propose to simply remove these functions in Python 3.12, and leave them broken (as they are, with the reference leak) in Python 3.11 (it's too late to remove these functions in a stable version). IMO it's better for developers to get a build error, rather than having to run the code and then see at runtime that these functions are badly broken.

@Yhg1s told me that I need an exception for the backward compatibility (PEP 387), so I ask you: can I please get an exception and remove these 4 functions in Python 3.12?

Metadata

Metadata

Assignees

No one assigned

    Labels

    PEPPython Enhancement Proposal

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions