Skip to content

Allow extensions to set a callback to be invoked when a type is modified #91051

Description

@mpage
mannequin
BPO 46895
Nosy @carljm, @DinoV, @itamaro, @mpage

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2022-03-01.22:16:51.046>
labels = ['interpreter-core', 'expert-C-API', 'type-feature', '3.11']
title = 'Allow extensions to set a callback to be invoked when a type is modified'
updated_at = <Date 2022-03-01.22:21:58.988>
user = 'https://github.com/mpage'

bugs.python.org fields:

activity = <Date 2022-03-01.22:21:58.988>
actor = 'mpage'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core', 'C API']
creation = <Date 2022-03-01.22:16:51.046>
creator = 'mpage'
dependencies = []
files = []
hgrepos = []
issue_num = 46895
keywords = []
message_count = 1.0
messages = ['414305']
nosy_count = 4.0
nosy_names = ['carljm', 'dino.viehland', 'itamaro', 'mpage']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue46895'
versions = ['Python 3.11']

Linked PRs

Activity

  1. mpage commented on Mar 1, 2022

    mpagemannequin
    MannequinAuthor

    CPython extensions providing optimized execution of Python bytecode (e.g. the Cinder JIT), or even CPython itself (e.g. the faster-cpython project) may wish to cache access to lookups in the class hierarchy (e.g. when resolving the target of a method call). Extensions that perform these optimizations need to know when to invalidate the cached values. CPython already has a mechanism to invalidate its internal state (e.g. the global method cache) when a type is modified: _PyType_Modified. We propose adding an API to allow extensions to set a callback that will be invoked by _PyType_Modified whenever a type, or any ancestor of the type in the class hierarchy, changes.

    Proposed API:

    // A callback to be invoked with the modified type and optionally the name of
    // the attribute that was modified.
    typedef void(*PyType_ModifiedCallback)(PyTypeObject* type, PyObject* attr);
    
    // Set or get the callback. The callback may be cleared by supplying a NULL callback.
    void PyType_SetModifiedCallback(PyType_ModifiedCallback callback);
    PyType_ModifiedCallback PyType_GetModifiedCallback();
    
  2. changed the title [-]Type-Modified Callbacks[/-] [+]Allow extensions to set a callback to be invoked when a type is modified[/+] on Mar 1, 2022
  3. changed the title [-]Type-Modified Callbacks[/-] [+]Allow extensions to set a callback to be invoked when a type is modified[/+] on Mar 1, 2022
  4. transferred this issue fromon Apr 10, 2022
  5. gvanrossum commented on Sep 15, 2022

    @gvanrossum
    Member

    I don't see any discussion here. Are you still interested in getting this in 3.12? What should happen next? Is it a simple PR, or should we have a design discussion first?

  6. itamaro commented on Sep 15, 2022

    @itamaro
    Contributor

    Are you still interested in getting this in 3.12?

    yes, that's the plan!

    What should happen next? Is it a simple PR, or should we have a design discussion first?

    I think this is a simple PR (similar to #91054), so the next step is to write that PR if the proposed API looks reasonable

  7. 10 remaining items

  8. carljm commented on Dec 8, 2022

    @carljm
    Member

    Fixed in #91051.

  9. added 4 commits that reference this issue on Aug 11, 2023
  10. added a commit that references this issue on Aug 11, 2023
  11. added a commit that references this issue on Aug 16, 2023
  12. serhiy-storchaka commented on Aug 16, 2023

    @serhiy-storchaka
    Member

    Reopened because not all PRs were merged yet.

  13. added a commit that references this issue on Aug 16, 2023
  14. added a commit that references this issue on Aug 16, 2023
  15. added a commit that references this issue on Aug 16, 2023
  16. added a commit that references this issue on Aug 16, 2023
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

    3.12only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions