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

feat: add custom __dir__ for messages and message classes #289

Merged
merged 2 commits into from
Feb 7, 2022

Conversation

software-dov
Copy link
Contributor

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().

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
Copy link

codecov bot commented Feb 4, 2022

Codecov Report

❗ No coverage uploaded for pull request base (main@28aa3b2). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 28aa3b2...84868af. Read the comment docs.

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()))
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this do?

Copy link
Contributor Author

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.

@software-dov software-dov merged commit 35e019e into googleapis:main Feb 7, 2022
gcf-merge-on-green bot pushed a commit that referenced this pull request Feb 7, 2022
🤖 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).
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.

2 participants