Repository navigation
Allow extensions to set a callback to be invoked when a type is modified #91051
Description
Activity
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();Reacted by Oleg Iarygin, Itamar Oren and Erlend E. Aasland- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
on Mar 1, 2022 - changed the title
[-]Type-Modified Callbacks[/-][+]Allow extensions to set a callback to be invoked when a type is modified[/+]on Mar 1, 2022 - changed the title
[-]Type-Modified Callbacks[/-][+]Allow extensions to set a callback to be invoked when a type is modified[/+]on Mar 1, 2022 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?
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
10 remaining items
Fixed in #91051.
- added 4 commits that reference this issue
on Aug 11, 2023 - added a commit that references this issue
on Aug 16, 2023 Reopened because not all PRs were merged yet.
- added a commit that references this issue
on Aug 16, 2023 - added a commit that references this issue
on Aug 16, 2023
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:
bugs.python.org fields:
Linked PRs