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

gh-137317: fix inspect signature of class with descriptor wrapper#137862

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
serhiy-storchaka merged 14 commits intopython:mainfromyanyongyu:fix-issue-137317
Aug 28, 2025

Conversation

@yanyongyu
Copy link
Contributor

@yanyongyuyanyongyu commentedAug 16, 2025
edited
Loading

This PR fixes theinspect.signature behavior when inspecting a class that uses descriptor (like classmethod/staticmethod/custom) with a wrapped__init__.

This PR also adds more test cases not covered in PR#132055.

BalconyJH, KimigaiiWuyi, and cuso4huang reacted with hooray emoji
@python-cla-bot
Copy link

python-cla-botbot commentedAug 16, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply theskip news label instead.

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you for your PR,@yanyongyu. LGTM. 👍

I only have few minor suggestions for tests.

yihong0618 and yanyongyu reacted with heart emoji

withself.subTest('partial'):
classC:
__init__=identity(functools.partial(lambdax,a,b:None,2))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should not this befunctools.partial(identity(lambda x, a, b: None), 2)? Although the "partial" and "partialmethod" subtests are not affected by all these changes, so I am not sure that it makes sense to keep them. If they do not fail, we cannot be sure that they are meaningful.

Copy link
ContributorAuthor

@yanyongyuyanyongyuAug 28, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you for pointing out the error, I will correct this.

These test cases are based on the ones below (test_signature_on_class_with_init andtest_signature_on_class_with_new), and I believe they need to be this detailed to catch potential bugs from changes made ininspect.signature's behavior.

yihong0618 reacted with thumbs up emoji
Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM. 👍

@serhiy-storchaka
Copy link
Member

I added also tests for a wrapped metaclass'__call__. This is more rare than custom__new__ or__init__, but it uses the same mechanism. And renamed the decorators -- becauseidentity is usually a name of a function that returns its argument, this may be confusing.

yanyongyu reacted with thumbs up emoji

@serhiy-storchakaserhiy-storchaka merged commit025a213 intopython:mainAug 28, 2025
45 checks passed
@serhiy-storchakaserhiy-storchaka added needs backport to 3.13bugs and security fixes needs backport to 3.14bugs and security fixes labelsAug 28, 2025
@miss-islington-app
Copy link

Thanks@yanyongyu for the PR, and@serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks@yanyongyu for the PR, and@serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestAug 28, 2025
…t__ or __new__ (pythonGH-137862)Fixed several cases where __init__, __new__ or metaclass` __call__ is a descriptorthat returns a wrapped function.(cherry picked from commit025a213)Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestAug 28, 2025
…t__ or __new__ (pythonGH-137862)Fixed several cases where __init__, __new__ or metaclass` __call__ is a descriptorthat returns a wrapped function.(cherry picked from commit025a213)Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
@bedevere-app
Copy link

GH-138224 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelAug 28, 2025
@bedevere-app
Copy link

GH-138225 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelAug 28, 2025
@yanyongyuyanyongyu deleted the fix-issue-137317 branchAugust 28, 2025 15:07
serhiy-storchaka pushed a commit to miss-islington/cpython that referenced this pull requestAug 28, 2025
…t__ or __new__ (pythonGH-137862)Fixed several cases where __init__, __new__ or metaclass` __call__ is a descriptorthat returns a wrapped function.(cherry picked from commit025a213)Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
serhiy-storchaka pushed a commit that referenced this pull requestAug 28, 2025
…it__ or __new__ (GH-137862) (GH-138225)Fixed several cases where __init__, __new__ or metaclass` __call__ is a descriptorthat returns a wrapped function.(cherry picked from commit025a213)Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
lkollar pushed a commit to lkollar/cpython that referenced this pull requestSep 9, 2025
…t__ or __new__ (pythonGH-137862)Fixed several cases where __init__, __new__ or metaclass` __call__ is a descriptorthat returns a wrapped function.
vstinner pushed a commit that referenced this pull requestOct 8, 2025
…it__ or __new__ (GH-137862) (#138224)gh-137317: Fix inspect.signature() for class with wrapped __init__ or __new__ (GH-137862)Fixed several cases where __init__, __new__ or metaclass` __call__ is a descriptorthat returns a wrapped function.(cherry picked from commit025a213)Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@yanyongyu@serhiy-storchaka

[8]ページ先頭

©2009-2025 Movatter.jp