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: Add sys._getfunc
Type: enhancement Stage: patch review
Components: Interpreter Core Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: JelleZijlstra Nosy List: JelleZijlstra, Mark.Shannon, barry
Priority: normal Keywords: patch

Created on 2022-01-27 03:46 by JelleZijlstra, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 30950 open JelleZijlstra, 2022-01-27 04:20
Messages (2)
msg411833 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-01-27 03:46
sys._getframe() has to create frame objects, which is relatively expensive. Usually the calling function object should be enough.

See https://github.com/faster-cpython/ideas/discussions/238
msg412804 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2022-02-08 01:56
> Usually the calling function object should be enough.

I want to at least provide some historical context on why sys._getframe() exists.  I originally wrote that to support PEP 292 and internationalization in Mailman.  This has since been extracted into the flufl.i18n package.  Here is the use of sys._getframe() in that library:

https://gitlab.com/warsaw/flufl.i18n/-/blob/main/src/flufl/i18n/_translator.py#L65

You can see that the reason this exists is to dig out the local and globals of the context in which the _() function is invoked.  This greatly reduces the need to repeat yourself in i18n call sites.

https://flufli18n.readthedocs.io/en/stable/using.html#substitutions-and-placeholders

I'm not saying sys._getfunc() is or isn't useful, but it won't change original need for sys._getframe().
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90701
2022-02-08 01:56:28barrysetnosy: + barry
messages: + msg412804
2022-01-27 04:20:01JelleZijlstrasetkeywords: + patch
stage: patch review
pull_requests: + pull_request29129
2022-01-27 03:46:31JelleZijlstracreate