GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — inspect.signature doesn't always return a signature · Issue #66000 · python/cpython

inspect.signature doesn't always return a signature #66000

New issue
Copy link
New issue
Copy link
Closed
Closed
inspect.signature doesn't always return a signature#66000
Copy link
Assignees
1st1
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

PCManticore
mannequin
opened on Jun 18, 2014
Issue body actions
BPO 21801
Nosy @ncoghlan, @larryhastings, @PCManticore, @1st1
Files
  • inspect_signature.patch
  • issue21801.patch
  • 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/1st1'
    closed_at = <Date 2014-06-23.17:24:02.008>
    created_at = <Date 2014-06-18.12:41:45.841>
    labels = ['type-feature', 'library']
    title = "inspect.signature doesn't always return a signature"
    updated_at = <Date 2014-06-23.17:24:36.614>
    user = 'https://github.com/PCManticore'

    bugs.python.org fields:

    activity = <Date 2014-06-23.17:24:36.614>
    actor = 'yselivanov'
    assignee = 'yselivanov'
    closed = True
    closed_date = <Date 2014-06-23.17:24:02.008>
    closer = 'python-dev'
    components = ['Library (Lib)']
    creation = <Date 2014-06-18.12:41:45.841>
    creator = 'Claudiu.Popa'
    dependencies = []
    files = ['35682', '35710']
    hgrepos = []
    issue_num = 21801
    keywords = ['patch', 'needs review']
    message_count = 5.0
    messages = ['220936', '221103', '221114', '221368', '221369']
    nosy_count = 5.0
    nosy_names = ['ncoghlan', 'larry', 'Claudiu.Popa', 'python-dev', 'yselivanov']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue21801'
    versions = ['Python 3.4', 'Python 3.5']

    Activity

    1. PCManticore commented on Jun 18, 2014

      @PCManticore
      PCManticoremannequin
      on Jun 18, 2014
      MannequinAuthor
      More actions

      Hello. I noticed the following behaviour while working with xmlrpc proxy methods.

      >>> import inspect, xmlrpc.client
      >>> proxy = xmlrpc.client.ServerProxy('http://localhost:8000')
      >>> proxy.mul
      <xmlrpc.client._Method object at 0x03B0C890>
      >>> inspect.signature(proxy.mul)
      <xmlrpc.client._Method object at 0x03B0CC90>
      >>>

      Now, according to the documentation, inspect.signature should return a signature or fail, but in this case it returns the actual object, which is misleading at least. This happens because _Method implements a proxy __getattr__, any accessed attribute becoming again a _Method. At the same time, inspect.signature happily uses

      try:
      obj.__signature__
      except AttributeError:
      ...

      to obtain the signature, if present.

      The attached patch checks if __signature__ is an actual Signature object. I searched, but couldn't find any, if __signature__ can be anything, so I hope that this approach works.

    2. PCManticore
      added
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancementA feature request or enhancement
      on Jun 18, 2014
    3. 1st1 commented on Jun 20, 2014

      @1st1
      1st1
      on Jun 20, 2014
      Member
      More actions

      This behaviour is indeed a bug. However, I think that the solution you propose is wrong.

      If we ignore invalid contents of __signature__ we are masking a bug or incorrect behaviour. In this case, you should have checked the requested attribute name in '__getattr__', and return something other than _Method, if it is a '__signature__'.

      Please find attached a patch, that checks if __signature__ is an instance of Signature class, and raises a TypeError if it isn't.

    4. PCManticore commented on Jun 20, 2014

      @PCManticore
      PCManticoremannequin
      on Jun 20, 2014
      MannequinAuthor
      More actions

      Your patch looks good to me.

    5. 1st1
      self-assigned this
      on Jun 20, 2014
    6. python-dev commented on Jun 23, 2014

      @python-dev
      python-devmannequin
      on Jun 23, 2014
      Mannequin
      More actions

      New changeset cc0f5d6ccb70 by Yury Selivanov in branch '3.4':
      inspect: Validate that __signature__ is None or an instance of Signature.
      http://hg.python.org/cpython/rev/cc0f5d6ccb70

      New changeset fa5b985f0920 by Yury Selivanov in branch 'default':
      inspect: Validate that __signature__ is None or an instance of Signature.
      http://hg.python.org/cpython/rev/fa5b985f0920

    7. python-dev
      closed this as completedon Jun 23, 2014
    8. 1st1 commented on Jun 23, 2014

      @1st1
      1st1
      on Jun 23, 2014
      Member
      More actions

      Fixed in 3.4 and 3.5.
      Thanks for the bug report!

    9. ezio-melotti
      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

    • @1st1
      1st1

    Labels

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.