Skip to content

Add sys._getfunc #90701

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

Closed
JelleZijlstra opened this issue Jan 27, 2022 · 3 comments
Closed

Add sys._getfunc #90701

JelleZijlstra opened this issue Jan 27, 2022 · 3 comments
Assignees
Labels
3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@JelleZijlstra
Copy link
Member

BPO 46543
Nosy @warsaw, @markshannon, @JelleZijlstra
PRs
  • bpo-46543: add sys._getcaller #30950
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/JelleZijlstra'
    closed_at = None
    created_at = <Date 2022-01-27.03:46:31.723>
    labels = ['interpreter-core', 'type-feature', '3.11']
    title = 'Add sys._getfunc'
    updated_at = <Date 2022-02-08.01:56:28.885>
    user = 'https://github.com/JelleZijlstra'

    bugs.python.org fields:

    activity = <Date 2022-02-08.01:56:28.885>
    actor = 'barry'
    assignee = 'JelleZijlstra'
    closed = False
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2022-01-27.03:46:31.723>
    creator = 'JelleZijlstra'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46543
    keywords = ['patch']
    message_count = 2.0
    messages = ['411833', '412804']
    nosy_count = 3.0
    nosy_names = ['barry', 'Mark.Shannon', 'JelleZijlstra']
    pr_nums = ['30950']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue46543'
    versions = ['Python 3.11']

    @JelleZijlstra
    Copy link
    Member Author

    sys._getframe() has to create frame objects, which is relatively expensive. Usually the calling function object should be enough.

    See faster-cpython/ideas#238

    @JelleZijlstra JelleZijlstra added the 3.11 only security fixes label Jan 27, 2022
    @JelleZijlstra JelleZijlstra self-assigned this Jan 27, 2022
    @JelleZijlstra JelleZijlstra added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement 3.11 only security fixes labels Jan 27, 2022
    @JelleZijlstra JelleZijlstra self-assigned this Jan 27, 2022
    @JelleZijlstra JelleZijlstra added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Jan 27, 2022
    @warsaw
    Copy link
    Member

    warsaw commented Feb 8, 2022

    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().

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @JelleZijlstra
    Copy link
    Member Author

    Closing as we decided we didn't need it for 3.11. I'm happy to help implement a variation of this idea in the future if it is deemed to be useful.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants