@@ -57,6 +57,55 @@ Type Objects
57
57
modification of the attributes or base classes of the type.
58
58
59
59
60
+ .. c :function :: int PyType_AddWatcher (PyType_WatchCallback callback)
61
+
62
+ Register *callback* as a type watcher. Return a non-negative integer ID
63
+ which must be passed to future calls to :c:func:`PyType_Watch`. In case of
64
+ error (e.g. no more watcher IDs available), return ``-1`` and set an
65
+ exception.
66
+
67
+ .. versionadded:: 3.12
68
+
69
+
70
+ .. c:function:: int PyType_ClearWatcher(int watcher_id)
71
+
72
+ Clear watcher identified by *watcher_id* (previously returned from
73
+ :c:func: `PyType_AddWatcher `). Return ``0`` on success, ``-1`` on error (e.g.
74
+ if *watcher_id * was never registered.)
75
+
76
+ An extension should never call ``PyType_ClearWatcher`` with a *watcher_id*
77
+ that was not returned to it by a previous call to
78
+ :c:func:`PyType_AddWatcher`.
79
+
80
+ .. versionadded:: 3.12
81
+
82
+
83
+ .. c:function:: int PyType_Watch(int watcher_id, PyObject *type)
84
+
85
+ Mark *type * as watched. The callback granted *watcher_id * by
86
+ :c:func: `PyType_AddWatcher ` will be called whenever
87
+ :c:func: `PyType_Modified ` reports a change to *type *. (The callback may be
88
+ called only once for a series of consecutive modifications to *type *, if
89
+ :c:func: `PyType_Lookup ` is not called on *type * between the modifications;
90
+ this is an implementation detail and subject to change.)
91
+
92
+ An extension should never call ``PyType_Watch`` with a *watcher_id* that was
93
+ not returned to it by a previous call to :c:func:`PyType_AddWatcher`.
94
+
95
+ .. versionadded:: 3.12
96
+
97
+
98
+ .. c:type:: int (*PyType_WatchCallback)(PyObject *type)
99
+
100
+ Type of a type-watcher callback function.
101
+
102
+ The callback must not modify *type * or cause :c:func: `PyType_Modified ` to be
103
+ called on *type * or any type in its MRO; violating this rule could cause
104
+ infinite recursion.
105
+
106
+ .. versionadded :: 3.12
107
+
108
+
60
109
.. c :function :: int PyType_HasFeature (PyTypeObject *o, int feature)
61
110
62
111
Return non-zero if the type object *o * sets the feature *feature *.
0 commit comments