Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

inspect.signature returns incorrect result on a @staticmethod and a @classmethod #101293

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@heckad

Description

@heckad

Bug report

importinspectdeftest_1():classFooStaticmethod:@staticmethoddef__call__(cls,s,l,t):returntinstance=FooStaticmethod()instance(1,2,3,4)# Success call with 4 argsassertlist(inspect.signature(instance).parameters.keys())== ['cls','s','l','t']deftest_2():classFooClassmethod:@classmethoddef__call__(cls,s,l,t):returntinstance=FooClassmethod()instance(1,2,3)# Success call with 4 argsassertlist(inspect.signature(instance).parameters.keys())== ['s','l','t']deftest_3():classFooStaticmethod:@staticmethoddef__call__():returnNoneinstance=FooStaticmethod()instance()assertlist(inspect.signature(instance).parameters.keys())== []

Your environment

CPython versions tested on:

  • Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] on win32
  • Python 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win32

Possible fix

The problem is that we are calling_signature_from_callable twice withskip_bound_arg=True.
A simple solution is to call_get_signature_of withskip_bound_arg=False on

sig=_get_signature_of(call)

That fix thetest_2 but not thetest_1. I need to think about how to do better. I will be glad to your suggestions.

Р.S I would like to submit a pull request.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp