This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sys._getframe audit event has frame as argument in 3.8-3.10
Type: Stage:
Components: Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Dutcho, steve.dower
Priority: normal Keywords:

Created on 2022-04-01 18:47 by Dutcho, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg416506 - (view) Author: (Dutcho) Date: 2022-04-01 18:47
Documentation (https://docs.python.org/3/library/audit_events.html and https://docs.python.org/3/library/sys.html#sys._getframe) states that `sys._getframe()` "raises [...] an auditing event with no arguments".
However, Python 3.8-3.10 provide the frame as argument to the hook function. Python 3.11 behaves consistently with documentation.
But I couldn't find the change mentioned in the change log. Therefore, I'm uncertain whether that's intentional or not, so whether it'll remain in the release version.

This is demonstrated by running snippet `audit.py`
```
import sys
sys.addaudithook(print)
print(sys.version)
sys._getframe()
```
in various versions:
```
3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]
sys._getframe (<frame at 0x00000209AD68C440, file 'audit.py', line 4, code <module>>,)

3.9.11 (tags/v3.9.11:2de452f, Mar 16 2022, 14:33:45) [MSC v.1929 64 bit (AMD64)]
sys._getframe (<frame at 0x00000199B7593FD0, file 'C:\\Users\\...\\audit.py', line 4, code <module>>,)

3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)]
sys._getframe (<frame at 0x00000210B95E9C40, file 'C:\\Users\\...\\audit.py', line 4, code <module>>,)

3.11.0a6 (main, Mar  7 2022, 16:46:19) [MSC v.1929 64 bit (AMD64)]
sys._getframe ()
```
msg416554 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2022-04-02 13:14
This should be fixed in the docs and also in 3.11. Now that we've shipped releases that include the frame, we should keep doing it.

If it's impossible to get a frame object in 3.11 (because it would deoptimize all the work that's been done there), it should pass None. Changing the value of the argument is fine, but changing the schema is not.
History
Date User Action Args
2022-04-11 14:59:58adminsetgithub: 91348
2022-04-02 13:14:53steve.dowersetmessages: + msg416554
versions: + Python 3.11
2022-04-01 20:26:07xtreaksetnosy: + steve.dower
2022-04-01 18:47:06Dutchocreate