Skip to content

Commit ab1e33c

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Add patch 'add-function-qualname-event'
Summary: This diff adds a patch to the `3.14` Meta-internal fork. Backport Python 3.15's change notification for qualnames on function objects Reviewed By: itamaro Differential Revision: D84384903 fbshipit-source-id: 637405160201607a6d23f85896f219c9a37cd299
1 parent 9615662 commit ab1e33c

4 files changed

Lines changed: 11 additions & 1 deletion

File tree

Doc/c-api/function.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ There are a few functions specific to Python functions.
175175
176176
.. versionadded:: 3.12
177177
178+
- ``PyFunction_PYFUNC_EVENT_MODIFY_QUALNAME``
179+
180+
.. versionadded:: 3.15
178181
179182
.. c:type:: int (*PyFunction_WatchCallback)(PyFunction_WatchEvent event, PyFunctionObject *func, PyObject *new_value)
180183

Include/cpython/funcobject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *);
134134
V(DESTROY) \
135135
V(MODIFY_CODE) \
136136
V(MODIFY_DEFAULTS) \
137-
V(MODIFY_KWDEFAULTS)
137+
V(MODIFY_KWDEFAULTS) \
138+
V(MODIFY_QUALNAME)
138139

139140
typedef enum {
140141
#define PY_DEF_EVENT(EVENT) PyFunction_EVENT_##EVENT,

Lib/test/test_capi/test_watchers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ def myfunc():
514514
_testcapi.set_func_kwdefaults_via_capi(myfunc, new_kwdefaults)
515515
self.assertIn((_testcapi.PYFUNC_EVENT_MODIFY_KWDEFAULTS, myfunc, new_kwdefaults), events)
516516

517+
new_qualname = "foo.bar"
518+
myfunc.__qualname__ = new_qualname
519+
self.assertIn((_testcapi.PYFUNC_EVENT_MODIFY_QUALNAME, myfunc, new_qualname), events)
520+
517521
# Clear events reference to func
518522
events = []
519523
del myfunc

Objects/funcobject.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ handle_func_event(PyFunction_WatchEvent event, PyFunctionObject *func,
6262
case PyFunction_EVENT_MODIFY_CODE:
6363
case PyFunction_EVENT_MODIFY_DEFAULTS:
6464
case PyFunction_EVENT_MODIFY_KWDEFAULTS:
65+
case PyFunction_EVENT_MODIFY_QUALNAME:
6566
RARE_EVENT_INTERP_INC(interp, func_modification);
6667
break;
6768
default:
@@ -746,6 +747,7 @@ func_set_qualname(PyObject *self, PyObject *value, void *Py_UNUSED(ignored))
746747
"__qualname__ must be set to a string object");
747748
return -1;
748749
}
750+
handle_func_event(PyFunction_EVENT_MODIFY_QUALNAME, (PyFunctionObject *) op, value);
749751
Py_XSETREF(op->func_qualname, Py_NewRef(value));
750752
return 0;
751753
}

0 commit comments

Comments
 (0)