-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-105080: Fixed inconsistent signature on derived classes #105217
Conversation
Thanks @gaogaotiantian for the PR, and @carljm for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
…honGH-105217) (cherry picked from commit 9ad199b) Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
GH-105257 is a backport of this pull request to the 3.12 branch. |
Thanks @gaogaotiantian for the PR, and @carljm for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Sorry, @gaogaotiantian and @carljm, I could not cleanly backport this to |
…es (pythonGH-105217). (cherry picked from commit 9ad199b) Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
…es (pythonGH-105217). (cherry picked from commit 9ad199b) Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
GH-105274 is a backport of this pull request to the 3.11 branch. |
For the code above,
inspect.signature(D2)
will give a different result thaninspect.signature(D1)
, which is counter-intuitive. This also affectshelp(D2)
vshelp(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.