https://github.com/python/cpython/commit/ff7bb565d836162eed0851c36afa325a107a5a56
commit: ff7bb565d836162eed0851c36afa325a107a5a56
branch: main
author: Dino Viehland <[email protected]>
committer: DinoV <[email protected]>
date: 2025-10-10T15:25:38-07:00
summary:
gh-139924: Add PyFunction_PYFUNC_EVENT_MODIFY_QUALNAME event for function
watchers (#139925)
Add PyFunction_PYFUNC_EVENT_MODIFY_QUALNAME event for function watchers
files:
A Misc/NEWS.d/next/C_API/2025-10-10-20-59-07.gh-issue-139924.ALByCb.rst
M Doc/c-api/function.rst
M Include/cpython/funcobject.h
M Lib/test/test_capi/test_watchers.py
M Objects/funcobject.c
diff --git a/Doc/c-api/function.rst b/Doc/c-api/function.rst
index 5fb8567ef8c95f..764b2ac610be4d 100644
--- a/Doc/c-api/function.rst
+++ b/Doc/c-api/function.rst
@@ -175,6 +175,9 @@ There are a few functions specific to Python functions.
.. versionadded:: 3.12
+ - ``PyFunction_PYFUNC_EVENT_MODIFY_QUALNAME``
+
+ .. versionadded:: 3.15
.. c:type:: int (*PyFunction_WatchCallback)(PyFunction_WatchEvent event,
PyFunctionObject *func, PyObject *new_value)
diff --git a/Include/cpython/funcobject.h b/Include/cpython/funcobject.h
index 598cd330bc9ca9..9e1599a7648564 100644
--- a/Include/cpython/funcobject.h
+++ b/Include/cpython/funcobject.h
@@ -134,7 +134,8 @@ PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *);
V(DESTROY) \
V(MODIFY_CODE) \
V(MODIFY_DEFAULTS) \
- V(MODIFY_KWDEFAULTS)
+ V(MODIFY_KWDEFAULTS) \
+ V(MODIFY_QUALNAME)
typedef enum {
#define PY_DEF_EVENT(EVENT) PyFunction_EVENT_##EVENT,
diff --git a/Lib/test/test_capi/test_watchers.py
b/Lib/test/test_capi/test_watchers.py
index 8644479d83d5ed..bef72032513da5 100644
--- a/Lib/test/test_capi/test_watchers.py
+++ b/Lib/test/test_capi/test_watchers.py
@@ -514,6 +514,10 @@ def myfunc():
_testcapi.set_func_kwdefaults_via_capi(myfunc, new_kwdefaults)
self.assertIn((_testcapi.PYFUNC_EVENT_MODIFY_KWDEFAULTS, myfunc,
new_kwdefaults), events)
+ new_qualname = "foo.bar"
+ myfunc.__qualname__ = new_qualname
+ self.assertIn((_testcapi.PYFUNC_EVENT_MODIFY_QUALNAME, myfunc,
new_qualname), events)
+
# Clear events reference to func
events = []
del myfunc
diff --git
a/Misc/NEWS.d/next/C_API/2025-10-10-20-59-07.gh-issue-139924.ALByCb.rst
b/Misc/NEWS.d/next/C_API/2025-10-10-20-59-07.gh-issue-139924.ALByCb.rst
new file mode 100644
index 00000000000000..a53d5d068d7d86
--- /dev/null
+++ b/Misc/NEWS.d/next/C_API/2025-10-10-20-59-07.gh-issue-139924.ALByCb.rst
@@ -0,0 +1 @@
+Function watchers can now receive a PyFunction_PYFUNC_EVENT_MODIFY_QUALNAME
event when a watched functions qualname is changed.
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index d8a10075578087..43198aaf8a7048 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -62,6 +62,7 @@ handle_func_event(PyFunction_WatchEvent event,
PyFunctionObject *func,
case PyFunction_EVENT_MODIFY_CODE:
case PyFunction_EVENT_MODIFY_DEFAULTS:
case PyFunction_EVENT_MODIFY_KWDEFAULTS:
+ case PyFunction_EVENT_MODIFY_QUALNAME:
RARE_EVENT_INTERP_INC(interp, func_modification);
break;
default:
@@ -747,6 +748,7 @@ func_set_qualname(PyObject *self, PyObject *value, void
*Py_UNUSED(ignored))
"__qualname__ must be set to a string object");
return -1;
}
+ handle_func_event(PyFunction_EVENT_MODIFY_QUALNAME, (PyFunctionObject *)
op, value);
Py_XSETREF(op->func_qualname, Py_NewRef(value));
return 0;
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]