GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Please add `PyObject_CallFinalizerFromDealloc()` to stable ABI · Issue #146063 · python/cpython

Please add PyObject_CallFinalizerFromDealloc() to stable ABI #146063

New issue
Copy link
New issue
Copy link
Closed
Closed
Please add PyObject_CallFinalizerFromDealloc() to stable ABI#146063
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-featureA feature request or enhancementA feature request or enhancement

Description

@davidhewitt
davidhewitt
opened on Mar 17, 2026
Issue body actions

Feature or enhancement

Proposal:

Please add PyObject_CallFinalizer and PyObject_CallFinalizerFromDealloc to the stable ABI.

The documentation for PyObject_CallFinalizer and PyObject_CallFinalizerFromDealloc state:

Call this function (or PyObject_CallFinalizerFromDealloc()) instead of calling tp_finalize directly because this function may deduplicate multiple calls to tp_finalize. Currently, calls are only deduplicated if the type supports garbage collection (i.e., the Py_TPFLAGS_HAVE_GC flag is set); this may change in the future.

These functions are not yet in the stable ABI. I believe it is possible to approximate their current behavior using PyObject_GC_IsFinalized (which is stable ABI) to decide whether to call the finalizer. Given the documentation states that the logic for deduplicating calls may change in future, it seems better to just add the functions to the stable ABI rather than leave downstream users to recreate their logic.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-146063: Add PyObject_CallFinalizerFromDealloc() to the limited C API #146172

Activity

  1. davidhewitt
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Mar 17, 2026
  2. vstinner
    added
    topic-C-API
    on Mar 19, 2026
  3. vstinner
    added a commit that references this issue on Mar 19, 2026

    pythongh-146063: Add PyObject_CallFinalizer() to the limited C API

    ba44a2e
  4. vstinner commented on Mar 19, 2026

    @vstinner
    vstinner
    on Mar 19, 2026
    Member
    More actions

    I wrote #146172 to add PyObject_CallFinalizer() and PyObject_CallFinalizerFromDealloc() to the limited C API.

    Reacted by David Hewitt
  5. colesbury commented on Mar 19, 2026

    @colesbury
    colesbury
    on Mar 19, 2026
    Contributor
    More actions

    Exposing PyObject_CallFinalizerFromDealloc makes sense, but is PyObject_CallFinalizer needed? We have only one internal usage in _PyIOBase_finalize, and I'm not even sure that code path is ever taken.

    I don't really see any external usages, except people re-exposing or binding it: https://grep.app/search?regexp=true&q=PyObject_CallFinalizer%5C%28

  6. davidhewitt commented on Mar 19, 2026

    @davidhewitt
    davidhewitt
    on Mar 19, 2026
    ContributorAuthor
    More actions

    I could support having just PyObject_CallFinalizerFromDealloc, that was the indeed the one that we were looking at in PyO3.

  7. vstinner
    changed the title [-]Please add `PyObject_CallFinalizer` (& `FromDealloc` variant) to stable ABI[/-] [+]Please add `PyObject_CallFinalizerFromDealloc()` to stable ABI[/+] on Mar 20, 2026
  8. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Mar 20, 2026
  9. da-woods commented on Mar 23, 2026

    @da-woods
    da-woods
    on Mar 23, 2026
    Contributor
    More actions

    Cython has missed this API too. I think I came to the conclusion that I could reimplement PyObject_CallFinalizer (with PyType_GetSlot and a function call, but I couldn't see any way of marking an object as finalized after calling it.

    (Edit: Looking at the code, it's actually marked as finalized inside PyObject_CallFinalizer so it wouldn't be possible to reimplement this.... Either way, we have no real need to manually call a finalizer outside of dealloc)

    Here's a previous discussion that didn't get a whole lot of interest: https://discuss.python.org/t/fully-support-using-the-tp-finalize-slot-of-a-pyobject-in-the-limited-api/69729

  10. encukou commented on Apr 14, 2026

    @encukou
    encukou
    on Apr 14, 2026
    Member
    More actions

    C API WG vote: capi-workgroup/decisions#104

  11. vstinner
    added a commit that references this issue on May 4, 2026

    gh-146063: Add PyObject_CallFinalizerFromDealloc() to the limited C A…

    ce51c18
  12. vstinner commented on May 13, 2026

    @vstinner
    vstinner
    on May 13, 2026
    Member
    More actions

    PyObject_CallFinalizerFromDealloc() has been added to Python 3.15: https://docs.python.org/dev/c-api/lifecycle.html#c.PyObject_CallFinalizerFromDealloc. The function was added to the stable ABI as well.

  13. vstinner
    closed this as completedon May 13, 2026
  14. davidhewitt commented on May 13, 2026

    @davidhewitt
    davidhewitt
    on May 13, 2026
    ContributorAuthor
    More actions

    Many thanks!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.