Repository navigation
C API: Add PyWeakref_GetRef() function #105927
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jun 19, 2023 [...] or NULL if the object has been finalized.
With an error set? If no, would you need to call
PyErr_Occurred()to find out if an error has occurred? See also capi-workgroup/problems#1- added 7 commits that reference this issue
on Jun 19, 2023 With an error set? If no, would you need to call PyErr_Occurred() to find out if an error has occurred? See also capi-workgroup/problems#1
No error is set. See PR #105929 for the first part of the implementation.
No error is set. See PR #105929 for the first part of the implementation.
Would it be better to return None if the object has been finalized? The idiom is that APIs returning a
PyObjectpointer only will returnNULLin case of error.45 remaining items
- added a commit that references this issue
on Jun 23, 2023 - added a commit that references this issue
on Jun 26, 2023 Oh, PEP 703 – Making the Global Interpreter Lock Optional in CPython proposes PyWeakref_FetchObject() which is more or less the PyWeakref_GetRef() function that was just added to Python 3.13.
I added
PyWeakref_GetRef()functions and deprecated PyWeakref_GetObject() and PyWeakref_GET_OBJECT() functions. I close the issue.- added 2 commits that reference this issue
on Apr 2, 2024
PyWeakref_GET_OBJECT() and PyWeakref_GetObject() return a borrowed reference to the object, or a borrowed reference to None if the object has been finalized. This API is error-prone and not easy to use.
This API was discussed in 2016: https://mail.python.org/archives/list/python-dev@python.org/thread/6BIPI4MCMAZFLJNIZB4JLTBW2COCACQQ/
I propose adding a new PyWeakref_GetRef() C API function which returns a new strong reference to the object, or NULL if the object has been finalized.
Linked PRs