-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Disable implicit conversion of 0
to pybind11::handle
.
#4008
Merged
rwgk
merged 19 commits into
pybind:master
from
rwgk:implicit_conversion_from_0_to_handle
Jul 14, 2022
Merged
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ca8d9fd
Disable implicit conversion from `0` to `pybind11::handle`.
21aa772
Reverse or-ed condition in an attempt to resolve GCC 8.3.0 errors (i3…
4ff51fd
Trying the simpler `std::is_same<T, PyObject *>`
e322611
Add implicit_conversion_from_pytorch_THPObjectPtr_to_handle test.
02fdc20
Accommodate types with implicit conversions to `PyObject *`, other th…
75317d8
Fix copy-paste mishap (picked wrong name).
05283e2
Revamp SFINAE construct to actually fix the pytorch issue (already va…
5410da7
Use `NOLINT(performance-noexcept-move-constructor)` for reduced code …
ded9c66
Use any_of, all_of, negation. It turns out to clang-format nicer.
6aa92e1
Clean up comments for changed code.
468addb
Reduce pytorch situation further, add test for operator ... const.
bc22bc8
Use `none_of` as suggested by @skylion007
5340256
Add `pure_compile_tests_for_handle_from_PyObject_pointers()`
a2781c6
Fix inconsequential oversight (retested).
8e6ad64
Factor our `is_pyobj_ptr_or_nullptr_t` to make the SFINAE conditions …
0bb8284
Remove stray line (oversight).
dbab18a
Make the `pure_compile_tests_for_handle_from_PyObject_pointers()` "rh…
5d42ec7
Remove the temporary PYBIND11_UNDO_PR4008 `#ifdef`.
ac94635
Merge branch 'master' into implicit_conversion_from_0_to_handle
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 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 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 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
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.
This probably still isn't the best way to do this, will this match volatile, mutable etc pointers. I think we may need to use
detail::remove_cv<T>::type
or something similar here.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.
Also there is
detail::satisifies_none_of
for the std::is_same block, but i am not sure its that much cleaner. Might be a bit when using remove_cv_ref or other behavior.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.
Yeah I was still thinking about the cv cases.
The most important thing is to come up with corresponding unit tests first. Without we (me at least) are certain to get lost in the incomprehensible maze of C++ rules and special cases.
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.
@rwgk I feel as though some template library has to have this implemented already with all the edge cases we need and we can just use that.
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.
"feel" and "probably" comments like this are massively unhelpful.
You gave up really quickly (#4006).
I'm presenting a solution that is already globally tested.
If you think this can be done better, please show how.
With tests.
I'm always happy to accept something that is provably better, and will be happy to globally test that for you.
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.
Agreed. Apologies, I didn't intend to come off rude or dismissive of your efforts. I was just making a generic note for future discussions.
Thanks for providing this really helpful PR so far and testing against all the edge case in PyTorch. I just meant to comment on how surprised I was to find that disabling this troublesome implicit conversion in C++ is so difficult. Thanks for all the effort.
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.
@Skylion007 I added all the tests that I could think of (5340256) to validate that the only behavior change is to disable the implicit conversion from
0
tohandle
. I left a temporary#ifdef
in case you have ideas for additional tests, or want to validate yourself that the commented-out code fails to compile before and after this PR.Between
operator PyObject *()
test reduced from the wild (pytorch)operator PyObject *() const
testpure_compile_tests_for_handle_from_PyObject_pointers()
testsI think we are extremely well covered. Maybe the SFINAE constructs could be polished, but unless we have more additional tests that expose a hole, I'd say this is as good as it gets.
I want to rerun the global testing though, although I don't think the change to
none_of
would break anything.