Skip to content
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

[pydrake] Add dynamic_attr support to cpp_template_pybind #22037

Conversation

jwnimmer-tri
Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri commented Oct 14, 2024

Towards #22022.


This change is Reviewable

@jwnimmer-tri jwnimmer-tri force-pushed the pybind-template-class-dynamic-atrr branch from 81c3d29 to 05943c7 Compare October 15, 2024 13:56
@jwnimmer-tri jwnimmer-tri added priority: medium release notes: none This pull request should not be mentioned in the release notes and removed status: do not merge status: do not review labels Oct 15, 2024
@jwnimmer-tri jwnimmer-tri marked this pull request as ready for review October 15, 2024 13:56
@jwnimmer-tri
Copy link
Collaborator Author

+@rpoyner-tri for feature review, please.

Copy link
Contributor

@rpoyner-tri rpoyner-tri left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: needs at least two assigned reviewers

@jwnimmer-tri
Copy link
Collaborator Author

+@ggould-tri for platform review per schedule, please.

Copy link
Contributor

@ggould-tri ggould-tri left a comment

Choose a reason for hiding this comment

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

:lgtm:; test coverage question.

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: 1 unresolved discussion

a discussion (no related file):
I am surprised not to see test coverage of an actual python use of a dynamic attr on a bound class. Is that because that will be forthcoming in the next PR of the train?


Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 unresolved discussion

a discussion (no related file):

Previously, ggould-tri wrote…

I am surprised not to see test coverage of an actual python use of a dynamic attr on a bound class. Is that because that will be forthcoming in the next PR of the train?

The existing test case does set a dynamic attr in python. (The string literal with code is passed to eval.) Or did you mean that we only set an attribute, but not get it?

I think its fine to assume that py::dynamic_attr() is implemented correctly in pybind11, so the only thing the test case needs to prove is that we asked pybind11 to enable it, which the current test does prove. (If I bug the implementation and don't pass along the dynamic_attr request, the test fails.)


Copy link
Contributor

@ggould-tri ggould-tri left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! all discussions resolved, LGTM from assignees rpoyner-tri(platform),ggould-tri(platform)

a discussion (no related file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

The existing test case does set a dynamic attr in python. (The string literal with code is passed to eval.) Or did you mean that we only set an attribute, but not get it?

I think its fine to assume that py::dynamic_attr() is implemented correctly in pybind11, so the only thing the test case needs to prove is that we asked pybind11 to enable it, which the current test does prove. (If I bug the implementation and don't pass along the dynamic_attr request, the test fails.)

Yes, I had meant testing it from python code; py::dynamic_attr() is of course correctly implemented in pybind11 but I cannot tell from inspection that we have used it correctly and so would have tested in a .py file. But you have better knowledge of the bindings than I do so I will defer to your experience.


Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! all discussions resolved, LGTM from assignees rpoyner-tri(platform),ggould-tri(platform)

a discussion (no related file):

Previously, ggould-tri wrote…

Yes, I had meant testing it from python code; py::dynamic_attr() is of course correctly implemented in pybind11 but I cannot tell from inspection that we have used it correctly and so would have tested in a .py file. But you have better knowledge of the bindings than I do so I will defer to your experience.

Okay. I am happy with this somewhat basic smoke test. If this new feature doesn't work, then tons of new bindings updates will crash in their unit tests. It won't go unnoticed, just maybe not specifically pointed out by a narrow unit test.


@jwnimmer-tri jwnimmer-tri merged commit 10b4bde into RobotLocomotion:master Oct 15, 2024
9 checks passed
@jwnimmer-tri jwnimmer-tri deleted the pybind-template-class-dynamic-atrr branch October 15, 2024 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium release notes: none This pull request should not be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants