-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
cpp_const: Add ability to impose C++ const semantics in Python. #7884
cpp_const: Add ability to impose C++ const semantics in Python. #7884
Conversation
218b8f6
to
2e1e768
Compare
+@soonho-tri for feature review, if you have time, please. Review status: 0 of 8 files reviewed at latest revision, all discussions resolved. Comments from Reviewable |
You mean the |
2e1e768
to
aa85bbc
Compare
Reviewed 4 of 5 files at r1, 2 of 4 files at r2. Comments from Reviewable |
Reviewed 4 of 5 files at r1, 2 of 4 files at r2. a discussion (no related file): bindings/pydrake/util/BUILD.bazel, line 127 at r2 (raw file):
If I recall correctly, our convention is to have something more like third_party/wrapt/BUILD.bazel, line 23 at r2 (raw file):
TBD Does this go into the right place? Comments from Reviewable |
third_party/wrapt/BUILD.bazel, line 23 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
(Sorry, this was a note to myself. I'll follow-up later.) Comments from Reviewable |
Per f2f with @jwnimmer-tri, we looked into using Ubuntu Debian packages / Mac PIP packages. However, the Ubuntu package is tagged with Given this, will use a fork for the time being. I will add a TODO to drop the fork once later versions of Review status: 6 of 8 files reviewed at latest revision, 3 unresolved discussions. third_party/wrapt/BUILD.bazel, line 23 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
OK Actually, I'm realizing that I want this to go to Comments from Reviewable |
Reviewed 1 of 4 files at r2. bindings/pydrake/util/cpp_const.py, line 2 at r2 (raw file):
BTW Is bindings/pydrake/util/cpp_const.py, line 11 at r2 (raw file):
I am not sure what I, as a reader, am supposed to take away from reading this comment. bindings/pydrake/util/cpp_const.py, line 18 at r2 (raw file):
Probably requires pydoc class overview per styleguide? bindings/pydrake/util/cpp_const.py, line 27 at r2 (raw file):
FYI Access to this isn't called in a tight loop, so consider hiding it behind an accessor for privacy? Alternatively -- unclear why some members are private and some are public. bindings/pydrake/util/cpp_const.py, line 50 at r2 (raw file):
Unclear what bindings/pydrake/util/cpp_const.py, line 82 at r2 (raw file):
BTW Typo bindings/pydrake/util/cpp_const.py, line 98 at r2 (raw file):
Missing bindings/pydrake/util/cpp_const.py, line 111 at r2 (raw file):
Missing bindings/pydrake/util/cpp_const.py, line 117 at r2 (raw file):
Missing: bindings/pydrake/util/cpp_const.py, line 150 at r2 (raw file):
I couldn't figure out the reason for the 200 limit. bindings/pydrake/util/cpp_const.py, line 159 at r2 (raw file):
It took me a while before I realized that this was rebinding bindings/pydrake/util/cpp_const.py, line 194 at r2 (raw file):
BTW Meta No whitespace between bindings/pydrake/util/cpp_const.py, line 194 at r2 (raw file):
FYI I assume basically any kind of object could be passed in here? If yes, great. If not and there's things I shouldn't pass in here, then please document then. bindings/pydrake/util/cpp_const.py, line 232 at r2 (raw file):
Rule-of-3 duplication of this check (just calling the existing helper?). bindings/pydrake/util/cpp_const.py, line 244 at r2 (raw file):
Ditto for bindings/pydrake/util/cpp_const.py, line 257 at r2 (raw file):
Actually, it returns a functor that does so? Comments from Reviewable |
aa85bbc
to
007a0c9
Compare
Reviewed 1 of 5 files at r2, 1 of 16 files at r3. bindings/pydrake/util/cpp_const.py, line 26 at r3 (raw file):
FYI Should it be an error here if bindings/pydrake/util/test/cpp_const_test.py, line 4 at r3 (raw file):
FYI I am not loving Comments from Reviewable |
007a0c9
to
5bfad74
Compare
Review status: 0 of 12 files reviewed at latest revision, 21 unresolved discussions. bindings/pydrake/util/BUILD.bazel, line 127 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 2 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 11 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 27 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
OK bindings/pydrake/util/cpp_const.py, line 50 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 82 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 98 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 111 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 117 at r2 (raw file):
bindings/pydrake/util/cpp_const.py, line 150 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. Removed limit, and ensured that this only applies to bindings/pydrake/util/cpp_const.py, line 159 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 194 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 194 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 232 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 244 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
OK I'd prefer to keep it in-sync with other Python decorators, like Changed bindings/pydrake/util/cpp_const.py, line 257 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 26 at r3 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
OK I'd prefer not to restrict this. Most classes that I've seen do not indicate their members until bindings/pydrake/util/test/cpp_const_test.py, line 4 at r3 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. It's a convention used in Comments from Reviewable |
Review status: 0 of 12 files reviewed at latest revision, 14 unresolved discussions. a discussion (no related file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. Comments from Reviewable |
Review status: 0 of 12 files reviewed at latest revision, 13 unresolved discussions. bindings/pydrake/util/cpp_const.py, line 18 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. Comments from Reviewable |
Reviewed 13 of 16 files at r3, 2 of 2 files at r4. bindings/pydrake/util/cpp_const.py, line 117 at r2 (raw file): Previously, EricCousineau-TRI wrote…
OK Ah, yes! I misread the python docs. bindings/pydrake/util/cpp_const.py, line 244 at r2 (raw file): Previously, EricCousineau-TRI wrote…
Aha, I didn't realize (while reading) that these are intended to be used as Python decorators. In that case, the names make perfect sense, but the documentation is unclear. bindings/pydrake/util/cpp_const.py, line 26 at r3 (raw file): Previously, EricCousineau-TRI wrote…
OK Good point. bindings/pydrake/util/cpp_const.py, line 232 at r4 (raw file):
I guess we can't name it The warning seems dire enough (and correctly so) that the method name should perhaps reflect that? Or we could promise to fail-fast here if const checking got compiled out or disabled? Comments from Reviewable |
LGTM Modulo future changes from @soonho-tri review. Reviewed 2 of 16 files at r3. bindings/pydrake/BUILD.bazel, line 140 at r4 (raw file):
FYI Is the name bindings/pydrake/third_party/forward_files.bzl, line 6 at r4 (raw file):
BTW I believe its skylark style to use kwargs syntax ( Comments from Reviewable |
Review status: all files reviewed at latest revision, 5 unresolved discussions, some commit checks failed. a discussion (no related file):
... and that I can Comments from Reviewable |
Checkpoint. Reviewed 15 of 16 files at r3, 1 of 2 files at r4. bindings/pydrake/util/cpp_const.py, line 3 at r3 (raw file):
Can you explain why this is "semi-" transparent? bindings/pydrake/util/cpp_const.py, line 41 at r4 (raw file):
Is "a property is owned" the same as "the returned value should be bindings/pydrake/util/cpp_const.py, line 85 at r4 (raw file):
Is it a list of built-in methods available in Python bindings/pydrake/util/cpp_const.py, line 183 at r4 (raw file):
BTW, this can be just bindings/pydrake/util/cpp_const.py, line 232 at r4 (raw file):
FYI, I don't understand "the branching is designed not to fail in this case" part. Could you elaborate? Comments from Reviewable |
c3754fc
to
c0e71fe
Compare
Review status: 7 of 17 files reviewed at latest revision, 10 unresolved discussions. bindings/pydrake/BUILD.bazel, line 140 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. Made a rename across bindings/pydrake/third_party/forward_files.bzl, line 6 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 244 at r2 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 3 at r3 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 41 at r4 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 85 at r4 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 183 at r4 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 232 at r4 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. bindings/pydrake/util/cpp_const.py, line 232 at r4 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
Done. Comments from Reviewable |
Reviewed 10 of 10 files at r5. bindings/pydrake/third_party/forward_files.bzl, line 6 at r4 (raw file): Previously, EricCousineau-TRI wrote…
BTW also tools/skylark/pybind.bzl, line 156 at r5 (raw file):
BTW typo Comments from Reviewable |
Reviewed 10 of 10 files at r5. bindings/pydrake/util/cpp_const.py, line 166 at r5 (raw file):
BTW, I was wondering if it's safe to use double-underscore ( Comments from Reviewable |
c0e71fe
to
2c9ba2e
Compare
Review status: 14 of 17 files reviewed at latest revision, 2 unresolved discussions. bindings/pydrake/util/cpp_const.py, line 166 at r5 (raw file): Previously, soonho-tri (Soonho Kong) wrote…
Done. Added comments in tools/skylark/pybind.bzl, line 156 at r5 (raw file): Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Done. Comments from Reviewable |
Reviewed 1 of 16 files at r3, 3 of 3 files at r6. bindings/pydrake/util/cpp_const.py, line 166 at r5 (raw file): Previously, EricCousineau-TRI wrote…
SGTM! Comments from Reviewable |
Reviewed 1 of 16 files at r3, 3 of 3 files at r6. Comments from Reviewable |
2c9ba2e
to
8d36186
Compare
Reviewed 4 of 4 files at r7. Comments from Reviewable |
1 similar comment
Reviewed 4 of 4 files at r7. Comments from Reviewable |
Copying from #7841:
C++ Pybind Code - cpp_const_pybind_test_py.cc
Python Code, using C++ - cpp_const_pybind_test.py
This imports a portion of
wrapt
with slight modifications (shown in the commits), and enables the pure-Python portion of the feature.Please note that this PR exceeds the nominal line count due to third-party code; however, excluding the third party code, the line count is 421 insertions:
This change is