Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-46543: add sys._getcaller #30950

Closed
wants to merge 9 commits into from

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Jan 27, 2022

Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks sound. A couple of minor issues.

Doc/library/sys.rst Outdated Show resolved Hide resolved
Python/sysmodule.c Outdated Show resolved Hide resolved
@markshannon
Copy link
Member

I don't like the name _getfunc, as explained in faster-cpython/ideas#238 (comment)

@JelleZijlstra
Copy link
Member Author

Thanks, I'll go back to _getcaller based on the discussion on faster-cpython.

@gvanrossum gvanrossum changed the title bpo-46543: add sys._getfunc bpo-46543: add sys._getcaller Feb 8, 2022
@JelleZijlstra
Copy link
Member Author

@markshannon would you still like this to make it into 3.11?

@Fidget-Spinner
Copy link
Member

@JelleZijlstra I don't know about Mark, but personally I'd like to see it in 3.11. Would my review be enough? (I've held off reviewing since it's draft).

@markshannon
Copy link
Member

Unfortunately there are a few problems with this, which stem from function.__code__ being mutable.

  1. Promoting the use of sys._getcaller instead of sys._getframe is flawed when you want the code object, as the caller function's __code__ attribute may have changed so that sys._getcaller(1).__code__ != sys.getframe(1).f_code which would be surprising. Changing the __code__ attribute of a function is a weird thing to do, so this might be OK.
  2. As internal structs cease to be part of the C-API, we may be able to implement Speed up frame handling in Python-to-Python calls. faster-cpython/ideas#111 which would mean that a reference to the caller function would no longer be available.
  3. In terms of Python semantics, a frame is defined by the (code, globals, builtins, locals) quad, not by the function from which it originally derived. The API should probably reflect that.

This was my idea originally, sorry for not spotting these flaws earlier.

@gvanrossum
Copy link
Member

Then should we just close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants