You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow extensions to set a callback to be invoked when a type is modified #91051
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=Noneclosed_at=Nonecreated_at=<Date2022-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=<Date2022-03-01.22:21:58.988>user='https://github.com/mpage'
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
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?
Activity
mpage commentedon Mar 1, 2022
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:
[-]Type-Modified Callbacks[/-][+]Allow extensions to set a callback to be invoked when a type is modified[/+][-]Type-Modified Callbacks[/-][+]Allow extensions to set a callback to be invoked when a type is modified[/+]gvanrossum commentedon Sep 15, 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?
itamaro commentedon Sep 15, 2022
yes, that's the plan!
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
carljm commentedon Dec 8, 2022
Fixed in #91051.
pythongh-91051: fix segfault when using all 8 type watchers
pythongh-91051: fix segfault when using all 8 type watchers
pythongh-91051: fix segfault when using all 8 type watchers
gh-91051: fix segfault when using all 8 type watchers (#107853)
pythongh-91051: fix segfault when using all 8 type watchers (pythonGH…
pythongh-91051: fix type watcher test to be robust to existing watcher
serhiy-storchaka commentedon Aug 16, 2023
Reopened because not all PRs were merged yet.
[3.12] gh-91051: fix segfault when using all 8 type watchers (GH-107853…
pythongh-91051: fix type watcher test to be robust to existing watcher (
gh-91051: fix type watcher test to be robust to existing watcher (#10…
[3.12] gh-91051: fix type watcher test to be robust to existing watch…