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 — gh-105080: Fixed inconsistent signature on derived classes by gaogaotiantian · Pull Request #105217 · python/cpython

Conversation

@gaogaotiantian

@gaogaotiantian gaogaotiantian commented Jun 2, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
class B:
    def __new__(self, *args, **kwargs):
        return super().__new__(self)
    def __init__(self, value):
        self.value = value

class D1(B):
    def __init__(self, value):
        super().__init__(value)

class D2(D1):
    pass

For the code above, inspect.signature(D2) will give a different result than inspect.signature(D1), which is counter-intuitive. This also affects help(D2) vs help(D1).

We should keep the consistency for the signatures for derived classes (of course when the signature is not changed).

This is due to a corner case in inspect.signature() where only the direct defined __init__ and __new__ method on the class takes priority, then __new__ is always used if defined on any base classes. This fix searches __new__ and __init__ based on MRO and prioritize __new__ if both are defined on a base class.

  • Issue: The help function shows incorrect signature for subclass #105080

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gaogaotiantian
Fixed inconsistent signature on derived classes
062dedf
@bedevere-bot bedevere-bot added the awaiting review label Jun 2, 2023
@gaogaotiantian gaogaotiantian changed the title Fixed inconsistent signature on derived classes gh-105080: Fixed inconsistent signature on derived classes Jun 2, 2023
@bedevere-bot bedevere-bot mentioned this pull request Jun 2, 2023
The help function shows incorrect signature for subclass #105080
Closed
@gaogaotiantian
gaogaotiantian requested a review from carljm June 2, 2023 02:37
@blurb-it
📜🤖 Added by blurb_it.
8654fba
sunmy2019
sunmy2019 approved these changes Jun 2, 2023
View reviewed changes
@bedevere-bot bedevere-bot added awaiting core review and removed awaiting review labels Jun 2, 2023
carljm
carljm approved these changes Jun 2, 2023
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Jun 2, 2023
@carljm
carljm merged commit 9ad199b into python:main Jun 2, 2023
@bedevere-bot bedevere-bot removed the awaiting merge label Jun 2, 2023
@carljm carljm added the needs backport to 3.12 only security fixes label Jun 2, 2023
@miss-islington

miss-islington commented Jun 2, 2023

Copy link
Copy Markdown
Contributor

Thanks @gaogaotiantian for the PR, and @carljm for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 2, 2023
@gaogaotiantian @miss-islington
pythongh-105080: Fixed inconsistent signature on derived classes (pyt…
c0c60d0
…honGH-105217)

(cherry picked from commit 9ad199b)

Co-authored-by: Tian Gao <[email protected]>
@bedevere-bot

bedevere-bot commented Jun 2, 2023

Copy link
Copy Markdown

GH-105257 is a backport of this pull request to the 3.12 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 only security fixes label Jun 2, 2023
carljm pushed a commit that referenced this pull request Jun 2, 2023
@miss-islington @gaogaotiantian
[3.12] gh-105080: Fixed inconsistent signature on derived classes (GH…
d3922c4
…-105217) (#105257)

gh-105080: Fixed inconsistent signature on derived classes (GH-105217)
(cherry picked from commit 9ad199b)

Co-authored-by: Tian Gao <[email protected]>
@gaogaotiantian
gaogaotiantian deleted the fix-inconsistent-signature branch June 3, 2023 03:48
@carljm carljm added the needs backport to 3.11 only security fixes label Jun 3, 2023
@miss-islington

miss-islington commented Jun 3, 2023

Copy link
Copy Markdown
Contributor

Thanks @gaogaotiantian for the PR, and @carljm for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington

miss-islington commented Jun 3, 2023

Copy link
Copy Markdown
Contributor

Sorry, @gaogaotiantian and @carljm, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 9ad199ba36791711f596393ca9a20dbf118ef858 3.11

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington miss-islington assigned carljm Jun 3, 2023
gaogaotiantian added a commit to gaogaotiantian/cpython that referenced this pull request Jun 4, 2023
@gaogaotiantian
[3.11] pythongh-105080: Fixed inconsistent signature on derived class…
9c074b0
…es (pythonGH-105217).

(cherry picked from commit 9ad199b)

Co-authored-by: Tian Gao <[email protected]>
gaogaotiantian added a commit to gaogaotiantian/cpython that referenced this pull request Jun 4, 2023
@gaogaotiantian
[3.11] pythongh-105080: Fixed inconsistent signature on derived class…
3b2a8cc
…es (pythonGH-105217).

(cherry picked from commit 9ad199b)

Co-authored-by: Tian Gao <[email protected]>
@bedevere-bot

bedevere-bot commented Jun 4, 2023

Copy link
Copy Markdown

GH-105274 is a backport of this pull request to the 3.11 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jun 4, 2023
@erlend-aasland erlend-aasland mentioned this pull request Jun 6, 2023
3.12 backport gh 105236 #105358
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@carljm carljm carljm approved these changes
@sunmy2019 sunmy2019 sunmy2019 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@carljm carljm

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@gaogaotiantian @miss-islington @bedevere-bot @carljm @sunmy2019
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.