GeezerVison is showing github.com — gh-106917: fix super classmethod calls to non-classmethods by carljm · Pull Request #106977 · python/cpython
Conversation
carljm
commented
Jul 21, 2023
•
edited by bedevere-bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
The fix for #105035 was subtly incomplete. It checked that cls->tp_getattro == PyObject_GetGenericAttr (as a precondition for attempting the load-method optimization), but what we really need to know is that Py_TYPE(self)->tp_getattro == PyObject_GenericGetAttr. In the typical case of super(MyClass, instance)... these are effectively the same thing (instance will be an instance of MyClass), but in a classmethod super() call (super(MyClass, MyClass)...) they are quite different; the type of MyClass is type, which has a different tp_getattro.
For actual classmethods this was fine; the load-method optimization still works correctly for classmethods looked up on types. But it doesn't work for regular methods (plain function objects) looked up on types; those are just regular function calls with no bound method behavior.
It's pretty unusual to use classmethod-style super where the call target is a regular function, not a classmethod. But it can occur, e.g. if using super with __new__ and dynamically-assigned __new__ methods, as in #106917.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. This is quite the subtlety. LGTM in general. I just have a comment about the tests.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks @carljm for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Sorry, @carljm, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker e5d5522612e03af3941db1d270bf6caebf330b8a 3.12
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
facebook-github-bot
pushed a commit
to facebookincubator/MetaPython
that referenced
this pull request
Mar 30, 2025
Summary:
Fixes a couple of issues which are causing `test_super` to fail on 3.12:
1) We don't actually respect the global super object at all! We are using the exported Cinder function to implement this on 3.10, but just calling the equivalent of `Ci_Super_Lookup` on 3.12. Because we need to have the `global_super != &PySuper_Type` logic on 3.12 this just brings it over and stops exporting it from Cinder 3.10.
3) We get `no_args_in_super_call` backwards as oparg is effectively the number of arguments.
2) Ports the fix in python/cpython#106977 to the implementation of super in both the JIT and Cinder 3.10.
Reviewed By: alexmalyshev
Differential Revision: D71638145
fbshipit-source-id: 0f5a189d8cea573034e578c921925ce2988c3bb1
facebook-github-bot
pushed a commit
to facebookincubator/cinderx
that referenced
this pull request
Mar 30, 2025
Summary:
Fixes a couple of issues which are causing `test_super` to fail on 3.12:
1) We don't actually respect the global super object at all! We are using the exported Cinder function to implement this on 3.10, but just calling the equivalent of `Ci_Super_Lookup` on 3.12. Because we need to have the `global_super != &PySuper_Type` logic on 3.12 this just brings it over and stops exporting it from Cinder 3.10.
3) We get `no_args_in_super_call` backwards as oparg is effectively the number of arguments.
2) Ports the fix in python/cpython#106977 to the implementation of super in both the JIT and Cinder 3.10.
Reviewed By: alexmalyshev
Differential Revision: D71638145
fbshipit-source-id: 0f5a189d8cea573034e578c921925ce2988c3bb1
Reviewers
sunmy2019
Awaiting requested review from sunmy2019
Uh oh!
There was an error while loading. Please reload this page.
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.
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.
|