Skip to content

gh-137740: Clarify __del__ invocation mechanism in reference counting #137741

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 3 commits into
base: main
Choose a base branch
from

Conversation

robinnarsinghranabhat
Copy link

@robinnarsinghranabhat robinnarsinghranabhat commented Aug 13, 2025

Issue : gh-137740: Clarify reference counting details in "Thin Ice" section in extending documentation


📚 Documentation preview 📚: https://cpython-previews--137741.org.readthedocs.build/

@python-cla-bot
Copy link

python-cla-bot bot commented Aug 13, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Thanks for contributing, but I've been working on upstreaming this tutorial to replace this part of the documentation. We can go through the effort of reviewing and landing this if you want, but keep in mind that it will likely be lost soon anyway.

Comment on lines 1089 to 1091
which invokes the object's ``tp_dealloc`` function (``subtype_dealloc`` for Python
class instances). During deallocation, ``subtype_dealloc`` calls ``tp_finalize``,
which is mapped to the ``__del__`` method for Python classes (see :pep:`442`).
Copy link
Member

Choose a reason for hiding this comment

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

We need to use Sphinx references to link to the members here.

Choose a reason for hiding this comment

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

I have added references, to the best of my knowledge. Regardless of them being obsolete, I would really appreciate it to go through review process if possible, and get some feedbacks. They would help broaden my understanding, and I want to keep on supporting this project in ways I can.

Additionally, in your new tutorial, would it be possible to at keep something like this (thin ice) part. Normally, rigid examples like this gives an alternative perspective to understand things better, especially, for folks like me, new to cpython internals world.

Copy link
Member

Choose a reason for hiding this comment

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

I'll see if there's a place to work it in, but the idea is to completely change how we explain reference counting.

Normally, rigid examples like this gives an alternative perspective to understand things better, especially, for folks like me, new to cpython internals world.

Yeah, I agree, that's why we're going to drop this section and use a tutorial that's been battle-tested.

disposing of it will call its :meth:`!__del__` method.
disposing of it will call its :meth:`!__del__` method. Internally,
:c:func:`PyList_SetItem` calls :c:func:`Py_DECREF` on the replaced item,
which invokes replaced item's corrresponding
Copy link
Member

Choose a reason for hiding this comment

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

Typo:

Suggested change
which invokes replaced item's corrresponding
which invokes replaced item's corresponding

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

Successfully merging this pull request may close these issues.

4 participants