Skip to content

[ENH] cpython.weakref: Add PyWeakref_IsDead (and backport to Python < 3.14) #7869

Open

Description

@mkoeppe

Is your feature request related to a problem? Please describe.

In my code, I would like to do

PyWeakref_IsDead(...)

Describe the solution you'd like.

Add a declaration of PyWeakref_IsDead (https://docs.python.org/3/c-api/weakref.html#c.PyWeakref_IsDead, Python >= 3.14) to cpython.weakref.

Include a backport to Python < 3.14, as already done for PyWeakref_GetRef in
https://github.com/cython/cython/blob/master/Cython/Includes/cpython/weakref.pxd#L27

Describe alternatives you've considered.

Holding the strong reference and immediately releasing it.

Additional context

passagemath/passagemath#1787 (comment)

Activity

  1. scoder commented on Jul 30, 2026

    @scoder
    Contributor

    Note that you can always declare the function yourself in your code, similar to how it's done in weakref.pxd. But we'd be happy to receive a PR that adds it directly to that file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions