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

Add globalns and localns to the inspect.signature and inspect.Signature.from_callable #86126

Closed
isidentical opened this issue Oct 6, 2020 · 4 comments
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@isidentical
Copy link
Sponsor Member

BPO 41960
Nosy @gvanrossum, @1st1, @isidentical
PRs
  • bpo-41960: Add globalns and localns parameters to inspect.signature and Signature.from_callable #22583
  • 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 = None
    closed_at = <Date 2020-12-23.22:45:52.586>
    created_at = <Date 2020-10-06.20:39:01.138>
    labels = ['type-feature', 'library', '3.10']
    title = 'Add globalns and localns to the inspect.signature and inspect.Signature.from_callable'
    updated_at = <Date 2020-12-23.22:45:52.585>
    user = 'https://github.com/isidentical'

    bugs.python.org fields:

    activity = <Date 2020-12-23.22:45:52.585>
    actor = 'BTaskaya'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-12-23.22:45:52.586>
    closer = 'BTaskaya'
    components = ['Library (Lib)']
    creation = <Date 2020-10-06.20:39:01.138>
    creator = 'BTaskaya'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41960
    keywords = ['patch']
    message_count = 4.0
    messages = ['378137', '383219', '383648', '383663']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'yselivanov', 'BTaskaya']
    pr_nums = ['22583']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue41960'
    versions = ['Python 3.10']

    @isidentical
    Copy link
    Sponsor Member Author

    To resolve annotations in local namespaces (and possibly in different contexts), inspect.signature can take globalns and localns parameters.

    I'm not inclined to add these into the getfullargspec, but I'd appreciate any comments about whether it is a good idea or not!

    @isidentical isidentical added 3.10 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Oct 6, 2020
    @gvanrossum
    Copy link
    Member

    It's been a while, I've lost context for this idea. What problem are you trying to solve here? Are there issues where people have reported problems that this would allow them to solve?

    @isidentical
    Copy link
    Sponsor Member Author

    It's been a while, I've lost context for this idea. What problem are you trying to solve here? Are there issues where people have reported problems that this would allow them to solve?

    Context: #20434 (comment)

    tl;dr:
    import inspect

    def foo():
        class F: ...
        def foo(bar: F): ...
        print(inspect.signature(foo))
    
    foo()

    Normally, if inspect.signature is able to resolve annotations with the current globals()/locals() it will give the resolved version, if not the string version. So adding this would allow people to choose which namespace inspect.signature will pass to the typing.get_type_hints. (inspect.signature(foo, localns=locals()) would give directly the F object instead of 'F', etc.)

    @isidentical
    Copy link
    Sponsor Member Author

    New changeset eee1c77 by Batuhan Taskaya in branch 'master':
    bpo-41960: Add globalns and localns parameters to inspect.signature and Signature.from_callable (GH-22583)
    eee1c77

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants