-
Notifications
You must be signed in to change notification settings - Fork 1k
Avoid type checks in methods where CPython already guarantees the received type #5930
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
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
71c9365
speicialize self conversion for descriptor slots for which CPython do…
MatthieuDartiailh 3932d02
Implement trusted self conversion for all extension-type method and s…
Copilot c36a08d
tests: bless outputs
MatthieuDartiailh 831a855
Merge branch 'main' into descriptor
MatthieuDartiailh 8f685ee
add a news fragment
MatthieuDartiailh e2fbacf
address review comments
MatthieuDartiailh dd3d5eb
proper news fragment
MatthieuDartiailh fa19092
wip fixing tests
MatthieuDartiailh 0462993
attempt to fix test
MatthieuDartiailh 7170fda
fix broken tests
MatthieuDartiailh e86289e
Merge remote-tracking branch 'origin/main' into descriptor
MatthieuDartiailh cabbe9b
address review comment
MatthieuDartiailh ad0bf36
test: bless ui test
MatthieuDartiailh d449db0
test: disable 2 tests based on accessing __getattr__ from type object
MatthieuDartiailh 63d014f
tests: broader type ignore in tests testing with known wrong types
MatthieuDartiailh abdb347
Merge branch 'main' into descriptor
MatthieuDartiailh 00e8225
test: bless ui tests
MatthieuDartiailh d3fcc97
fix clippy warning
MatthieuDartiailh 33f6421
test: ui fix indentation
MatthieuDartiailh 1661553
Merge remote-tracking branch 'origin/main' into descriptor
MatthieuDartiailh 2a1240b
test; fix again bad indent in ui test
MatthieuDartiailh 93165c0
test: do not test for silly calls in pure Python
MatthieuDartiailh 25d9862
test: ui fix formatting
MatthieuDartiailh bba8597
Merge remote-tracking branch 'origin/main' into descriptor
MatthieuDartiailh 07921a4
address review comments
MatthieuDartiailh 16e9b0a
tests: attempt to fix ui tests
MatthieuDartiailh 28d5326
tests: attempt to fix ui tests
MatthieuDartiailh 4e30ed0
Revert "tests: attempt to fix ui tests"
MatthieuDartiailh f1daa3b
Merge remote-tracking branch 'origin/main' into descriptor
MatthieuDartiailh 0a9df8e
test: ui attempt to fix tests
MatthieuDartiailh afe4d36
fix bad indent
MatthieuDartiailh 0351c2a
Merge remote-tracking branch 'origin/main' into descriptor
MatthieuDartiailh 1916d80
revert bad changes to invalid_pyfunction_argument.default.stderr
MatthieuDartiailh 130b5f3
Merge remote-tracking branch 'origin/main' into descriptor
davidhewitt 80c7534
label SAFETY comments
davidhewitt 7ab495e
disable trusted optimization on PyPy
davidhewitt c76bd35
fixup richcmp on PyPy
davidhewitt 411c151
fix msrv build
davidhewitt 6ca12ea
fix clippy
davidhewitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Remove redundant type checks for methods where CPython guarantees the type of `self` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Perhaps, but I wonder if we are making a mistake by calling the runtime helper with the arguments swapped (we might not match CPython's behavior for
__add__/__radd__, for example). Maybe CPython always calls the slot withselfon the LHS? I cannot remember, worth checking.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.
https://github.com/python/cpython/blob/main/Include/cpython/object.h#L62-L64
mentions explicitly that nb_add must check both args.
The proper fix may be to alter define_pyclass_binary_operator_slot in pyo3 to check the argument and dispatch to
__add__and__radd__accordingly.This is technically what the code does since a failed extraction is turned into NotImplemented. It is somewhat convoluted which is why it took me a couple of iterations of this comment to get it right.
To me it looks wrong to call__radd__on the same object if__add__fails. I believe it should be called on the other object and this is the responsibility of CPython to make the call.