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: Skip creating redundant wrapper functions in ExitStack.callback
Type: performance Stage: resolved
Components: Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: barry, ncoghlan, pablogsal
Priority: normal Keywords:

Created on 2017-12-29 13:37 by ncoghlan, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg309171 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2017-12-29 13:37
While discussing https://bugs.python.org/issue32145, I noticed that ExitStack.callback *always* adds a wrapper function, even when the `args` and `kwds` parameters are both empty.

For plain callbacks that aren't receiving any extra arguments, it would be better to skip adding the redundant wrapper function.
msg309316 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2018-01-01 00:11
I think I am missing something because the callbacks are always called with (exc_type, exc, tb) (check here https://github.com/python/cpython/blob/176baa326be4ec2dc70ca0c054b7e2ab7ca6a9cf/Lib/contextlib.py#L475) and therefore a wrapper that just drops these arguments and calls the original callback with no arguments is always needed, right?
msg309356 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-01-02 07:13
Ah, you're right, I wasn't thinking clearly when I filed this - the correct public API method to transfer existing exit stack entries to a new stack would be "ExitStack.push()".

I'll make a note of that on the original issue.
History
Date User Action Args
2022-04-11 14:58:56adminsetgithub: 76626
2018-01-02 07:13:01ncoghlansetstatus: open -> closed
resolution: not a bug
messages: + msg309356

stage: needs patch -> resolved
2018-01-01 00:11:57pablogsalsetnosy: + pablogsal
messages: + msg309316
2017-12-29 13:37:44ncoghlancreate