[issue38892] Audit Hook doc typos and confusion
New submission from Terry J. Reedy <tjreedy@udel.edu>: Some suggestions for https://docs.python.org/3.9/c-api/sys.html#c.PySys_AddAuditHook https://docs.python.org/3.9/library/sys.html#sys.addaudithook "Adds to the collection of active auditing hooks" "Adds the callable hook to the collection of active auditing hooks" Change 'Adds' to 'Add' or maybe 'Append' (see near below). Insert 'the callable hook' in PySys version. Change 'collection' to 'sequence' or 'list' (and change verb to 'append') since order is important. PySys version: I think the 'userData' explanation should be closer to the top. Grammar: "Functions in the runtime and standard library that raise events include the details in each function’s documentation and listed in the audit events table." is not a proper sentence. Its 'skeleton' is "Functions ... include the details ... and listed ... . Either change 'include the details' to 'are detailed' and 'listed' to 'are listed' or split into two sentences: "Functions in the runtime and standard library that raise events are listed in the audit events table. Details are in each function’s documentation. Both, again: "raises a auditing event". 'a' should be 'an'. To me, this is slightly confusing because Python raises exceptions, but auditing events are not exceptions and do not normally abort execution. Perhaps "This call is a 'sys.addaudithook' event with no arguments that triggers an audit call." https://docs.python.org/3.9/c-api/sys.html#c.PySys_Audit https://docs.python.org/3.9/library/sys.html#sys.audit Change 'Raises' to 'Raise'. https://docs.python.org/3.8/library/audit_events.html On pydev, Steve said "(though some won't be raised until 3.8.1... we should probably mark those, or at least update that page to warn that events may have been added over time)." ---------- assignee: docs@python components: Documentation, Interpreter Core messages: 357240 nosy: christian.heimes, docs@python, steve.dower, terry.reedy priority: normal severity: normal stage: needs patch status: open title: Audit Hook doc typos and confusion type: behavior versions: Python 3.8, Python 3.9 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue38892> _______________________________________
Steve Dower <steve.dower@python.org> added the comment: Thanks Terry, this is great! Agree with everything apart from not liking "raise" - I think "raise an event" is totally fine usage, and certainly better than "triggers an audit call" (since it may not, if nobody's listening). Plus PEP 578 is full of "raise", and we're not going to go edit all of that :) ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue38892> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: I agree on consistency. I will make a PR for you to review. Do you think a minimal code example might help? Running ... import sys def hook(name, args): if name.startswith('compile'): print(name, args) sys.addaudithook(hook) compile('a = 1', '<dummy>', 'exec') # prints compile (b'a = 1', '<dummy>') My own interest is learning about the socket connecting an IDLE GUI process and the user code run process. The following in the two startup files: def hook(name, args): if name.startswith('socket'): print('I', name, args) # I/R in the IDLE/run processes. sys.addaudithook(hook) results in: I socket.gethostname () R socket.gethostname () I socket.bind (<socket.socket fd=796, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0>, ('127.0.0.1', 0)) R socket.bind (<socket.socket fd=796, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0>, ('127.0.0.1', 0)) R socket.connect (<socket.socket fd=816, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0>, ('127.0.0.1', 62119)) I socket.__new__ (<socket.socket fd=-1, family=AddressFamily.AF_UNSPEC, type=0, proto=0>, 2, 1, 0) R socket.__new__ (<socket.socket fd=-1, family=AddressFamily.AF_UNSPEC, type=0, proto=0>, 2, 1, 0) To go further, I might wrap socket.socket.send/recv with functions that call sys.audit. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue38892> _______________________________________
Change by Terry J. Reedy <tjreedy@udel.edu>: ---------- keywords: +patch pull_requests: +16846 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/17361 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue38892> _______________________________________
Steve Dower <steve.dower@python.org> added the comment: New changeset e563a155be60fc0757914f87c8138f10de00bb16 by Steve Dower (Terry Jan Reedy) in branch 'master': bpo-38892: Improve docs for audit event (GH-17361) https://github.com/python/cpython/commit/e563a155be60fc0757914f87c8138f10de0... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue38892> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +16873 pull_request: https://github.com/python/cpython/pull/17391 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue38892> _______________________________________
Steve Dower <steve.dower@python.org> added the comment: Thanks Terry! ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue38892> _______________________________________
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset 86d9933cc627c4232f9702ca0766713714ebbc53 by Miss Islington (bot) in branch '3.8': bpo-38892: Improve docs for audit event (GH-17361) https://github.com/python/cpython/commit/86d9933cc627c4232f9702ca0766713714e... ---------- nosy: +miss-islington _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue38892> _______________________________________
participants (3)
-
miss-islington
-
Steve Dower
-
Terry J. Reedy