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
sys.addaudithook() suppresses all Exception subclasses instead of only RuntimeError #152912
sys.addaudithook() suppresses all Exception subclasses when an existing audit hook raises. The documentation and the C API (PySys_AddAuditHook) both say only RuntimeError should be suppressed.
The Python-level sys.addaudithook(hook) at Python/sysmodule.c:530 fires the sys.addaudithook event to existing hooks. If a hook raises, the exception matcher checks against PyExc_Exception instead of PyExc_RuntimeError. Any Exception subclass prevents the new hook from being installed and returns None.
Actual result: A hook that raises ValueError (or any Exception subclass) during sys.addaudithook is silently suppressed, and the new hook is not installed.
Expected result: Only RuntimeError should be suppressed. Non-RuntimeError exceptions should propagate through sys.addaudithook().
The fix is in Python/sysmodule.c:530, changing PyExc_Exception to PyExc_RuntimeError.
importsysdefblocking_hook(*args):
raiseValueError("blocked")
sys.addaudithook(blocking_hook)
defmy_hook(*args):
print("This hook should have been installed")
sys.addaudithook(my_hook)
sys.audit("test")
Activity
pythongh-152912: Fix audit hook exception check in sys.addaudithook()
pythongh-152912: Fix audit hook exception check in sys.addaudithook()
pythongh-152912: Fix NEWS entry sphinx-lint warning
pythongh-152912: Fix stale C-API doc for PySys_AddAuditHook exception…
pythongh-152912: Move versionchanged note below versionadded in Doc/c…
gh-152912: Fix audit hook exception check in sys.addaudithook() (GH-1…
pythongh-152912: Fix audit hook exception check in sys.addaudithook() (…