-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat: add custom __dir__ for messages and message classes #289
Conversation
During development, it can be convenient to inspect objects and types directly to determine what methods and attributes they have using the dir() builtin command in a debugger or a REPL. Because proto-plus messages wrap their fields using __getattr__, the proto fields are not visible by default and must be explicitly exposed to dir().
Codecov Report
@@ Coverage Diff @@
## main #289 +/- ##
========================================
Coverage ? 100.00%
========================================
Files ? 22
Lines ? 983
Branches ? 219
========================================
Hits ? 983
Misses ? 0
Partials ? 0 Continue to review full report at Codecov.
|
names = {f_name for f_name in self._meta.fields.keys()} | ||
names.update(m.name for m in desc.nested_types) | ||
names.update(e.name for e in desc.enum_types) | ||
names.update(dir(object())) |
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.
What does this do?
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.
It's including all the fields message fields, nested message and enum types, and boilerplate methods and attributes inherited from object
. The important one is fields, since they weren't visible before, but since this is customizing __dir__
we need to explicitly add all the others back in too.
🤖 I have created a release *beep* *boop* --- ## [1.20.0](v1.19.9...v1.20.0) (2022-02-07) ### Features * add custom __dir__ for messages and message classes ([#289](#289)) ([35e019e](35e019e)) ### Bug Fixes * workaround for buggy pytest ([#291](#291)) ([28aa3b2](28aa3b2)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
During development, it can be convenient to inspect objects and types
directly to determine what methods and attributes they have using the
dir() builtin command in a debugger or a REPL.
Because proto-plus messages wrap their fields using getattr, the
proto fields are not visible by default and must be explicitly exposed
to dir().