Skip to content

operators: Explicitly expose py::hash(py::self) #2217

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 2 commits into from
May 31, 2020

Conversation

EricCousineau-TRI
Copy link
Collaborator

Add warnings about extending STL

When using pybind11 for Drake, I found that I had to write:

cls.def(py::detail::hash(py::self));

instead of what the unittest wrote:

.def(hash(py::self))

This explicitly exposes the overload in the pybind11 namespace.
Additionally, I was mislead into thinking that you may be able to overload std::abs. Per these docs, it does not appear to be valid (nor could I get it to work straight off the bat):
https://en.cppreference.com/w/cpp/language/extending_std

Follow-up to #1034

@EricCousineau-TRI EricCousineau-TRI force-pushed the feature-op-unary-named-fix branch from 44086d2 to f8a1099 Compare May 18, 2020 21:09
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me!
If easy: may be nice to undo whitespace formatting change after line 48 (old) of test_operator_overloading.py, so that it is obvious that the values aren't changed by this PR. (I'd also remove the extra empty line at the end.)

@EricCousineau-TRI
Copy link
Collaborator Author

@rwgk Thanks! However, it was still a tad hard for me to "add" in the new value b/c of whitespace changes.
Would it be OK if I instead curated my commits?
e.g. make minimal set of whitespace changes, no functional changes, and then add the functional change on top of that? Then bisecting / git history would be preserved!

@rwgk
Copy link
Collaborator

rwgk commented May 21, 2020 via email

@EricCousineau-TRI EricCousineau-TRI force-pushed the feature-op-unary-named-fix branch from f8a1099 to e4e62b3 Compare May 22, 2020 04:46
@EricCousineau-TRI EricCousineau-TRI force-pushed the feature-op-unary-named-fix branch from e4e62b3 to 2723387 Compare May 22, 2020 04:47
@EricCousineau-TRI
Copy link
Collaborator Author

EricCousineau-TRI commented May 22, 2020

Took about 3min to split the commits apart (and make sure each one tested correctly).
Lemme know what you think!

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Eric!

@wjakob
Copy link
Member

wjakob commented May 31, 2020

Looks great, thanks @EricCousineau-TRI and @rwgk for the review!

@wjakob wjakob merged commit 4e3d9fe into pybind:master May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants