Content-Length: 279691 | pFad | https://github.com/python/cpython/issues/127274

6B Defer functions defined in nested classes in free-threaded builds · Issue #127274 · python/cpython · GitHub
Skip to content

Defer functions defined in nested classes in free-threaded builds #127274

@mpage

Description

@mpage

Feature or enhancement

Proposal:

We currently only defer functions that do not have the CO_NESTED flag set:

if ((code_obj->co_flags & CO_NESTED) == 0) {
// Use deferred reference counting for top-level functions, but not
// nested functions because they are more likely to capture variables,
// which makes prompt deallocation more important.
_PyObject_SetDeferredRefcount((PyObject *)op);
}

This also excludes functions defined on nested classes. In the example below, the Foo.__init__ function will not use deferred reference counting because the __init__ method's code object has the CO_NESTED flag set.

def func():
    class Foo:
        def __init__(self):
            pass

We would like to relax the restriction on CO_NESTED to allow functions that are defined on nested classes to use deferred reference counting.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/127274

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy