Skip to content

gh-137791: Improve documentation for the reference counting changes in 3.14 #137819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ZeroIntensity
Copy link
Member

@ZeroIntensity ZeroIntensity commented Aug 15, 2025

@Fidget-Spinner
Copy link
Member

I don't know if this is what the OP actually meant. Negative reference counts might not be caused by the REFCNT(n) == 1 issue but rather some other symptom of the borrowed references that we use.

I hope the OP responds soon what they actually mean, and point to an actual issue/code.

@ZeroIntensity
Copy link
Member Author

Negative reference counts might not be caused by the REFCNT(n) == 1 issue but rather some other symptom of the borrowed references that we use.

Agreed. I'm trying to clarify that the borrowed reference changes only affect code in very niche cases.

references <strong reference>` is avoided in the Python interpreter. This
generally does not affect existing code, but C API extensions that checked
:c:func:`Py_REFCNT` of ``1`` to determine if an object is not referenced by
any other code should instead use :c:func:`PyUnstable_Object_IsUniqueReferencedTemporary`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't feel great to suggest people move from a (theoretically) stable Py_REFCNT(op) == 1 to an explicitly unstable PyUnstable_ function.

Can we explain why the function we suggest users port to is marked as unstable (e.g. that in reality, Py_REFCNT(op) == 1 was less stable than it appeared?).

Per Petr's comment on the issue, if this is strictly a breaking change, the note in refcounting.rst should probably be more explicit that in previous versions, the semantics around 1 and 0 were guaranteed, but that they no longer are.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is still guaranteed, as far as I know. I'll do my best to make things clearer otherwise.

Copy link
Member Author

@ZeroIntensity ZeroIntensity Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated both notes. Let me know if that looks any better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs Documentation in the Doc dir needs backport to 3.14 bugs and security fixes skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants