Skip to content

Commit 11f0f11

Browse files
bpo-38434: Fixes some audit event documentation (GH-16932)
(cherry picked from commit 894e30c) Co-authored-by: Steve Dower <steve.dower@python.org>
1 parent 4992dc6 commit 11f0f11

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

Doc/c-api/code.rst

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ bound into a function.
4040
can bind you to a precise Python version since the definition of the bytecode
4141
changes often.
4242
43-
.. audit-event:: code.__new__ code,filename,name,argcount,posonlyargcount,kwonlyargcount,nlocals,stacksize,flags c.PyCode_New
44-
4543
.. c:function:: PyCodeObject* PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, int nlocals, int stacksize, int flags, PyObject *code, PyObject *consts, PyObject *names, PyObject *varnames, PyObject *freevars, PyObject *cellvars, PyObject *filename, PyObject *name, int firstlineno, PyObject *lnotab)
4644
4745
Similar to :c:func:`PyCode_New`, but with an extra "posonlyargcount" for positonal-only arguments.

Doc/c-api/sys.rst

+10-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,16 @@ accessible to C code. They all work with the current interpreter thread's
330330
331331
See :pep:`578` for a detailed description of auditing. Functions in the
332332
runtime and standard library that raise events include the details in each
333-
function's documentation.
333+
function's documentation and listed in the :ref:`audit events table
334+
<audit-events>`.
335+
336+
.. audit-event:: sys.addaudithook "" c.PySys_AddAuditHook
337+
338+
If the interpreter is initialized, this function raises a auditing event
339+
``sys.addaudithook`` with no arguments. If any existing hooks raise an
340+
exception derived from :class:`Exception`, the new hook will not be
341+
added and the exception is cleared. As a result, callers cannot assume
342+
that their hook has been added unless they control all existing hooks.
334343
335344
.. versionadded:: 3.8
336345

Doc/library/sys.rst

+11-8
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,21 @@ always available.
3333
tuple of arguments. Native hooks added by :c:func:`PySys_AddAuditHook` are
3434
called first, followed by hooks added in the current interpreter.
3535

36-
Calling this function will trigger an event for all existing hooks, and if
37-
any raise an exception derived from :class:`Exception`, the add will be
38-
silently ignored. As a result, callers cannot assume that their hook has been
39-
added unless they control all existing hooks.
36+
.. audit-event:: sys.addaudithook "" sys.addaudithook
37+
38+
Raises a auditing event ``sys.addaudithook`` with no arguments. If any
39+
existing hooks raise an exception derived from :class:`Exception`, the
40+
new hook will not be added and the exception suppressed. As a result,
41+
callers cannot assume that their hook has been added unless they control
42+
all existing hooks.
4043

4144
.. versionadded:: 3.8
4245

4346
.. impl-detail::
4447

45-
When tracing is enabled, Python hooks are only traced if the callable has
46-
a ``__cantrace__`` member that is set to a true value. Otherwise, trace
47-
functions will not see the hook.
48+
When tracing is enabled (see :func:`settrace`), Python hooks are only
49+
traced if the callable has a ``__cantrace__`` member that is set to a
50+
true value. Otherwise, trace functions will skip the hook.
4851

4952

5053
.. data:: argv
@@ -87,7 +90,7 @@ always available.
8790
native function is preferred when possible.
8891

8992
See the :ref:`audit events table <audit-events>` for all events raised by
90-
``CPython``.
93+
CPython.
9194

9295
.. versionadded:: 3.8
9396

Doc/library/types.rst

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ Standard names are defined for the following types:
138138

139139
The type for code objects such as returned by :func:`compile`.
140140

141+
.. audit-event:: code.__new__ code,filename,name,argcount,posonlyargcount,kwonlyargcount,nlocals,stacksize,flags CodeType
142+
143+
Note that the audited arguments may not match the names or positions
144+
required by the initializer.
141145

142146
.. data:: CellType
143147

Doc/reference/simple_stmts.rst

+1
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ the :ref:`relativeimports` section.
839839
:func:`importlib.import_module` is provided to support applications that
840840
determine dynamically the modules to be loaded.
841841

842+
.. audit-event:: import module,filename,sys.path,sys.meta_path,sys.path_hooks import
842843

843844
.. _future:
844845

0 commit comments

Comments
 (0)