Skip to content

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

Closed

Description

@isidentical
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']

    Activity

    1. isidentical commented on Oct 6, 2020

      @isidentical
      SponsorMemberAuthor

      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!

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancement
      on Oct 6, 2020
    3. gvanrossum commented on Dec 17, 2020

      @gvanrossum
      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?

    4. isidentical commented on Dec 23, 2020

      @isidentical
      SponsorMemberAuthor

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

    5. isidentical commented on Dec 23, 2020

      @isidentical
      SponsorMemberAuthor

      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

    6. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions