GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add custom __dir__ for messages and message classes by software-dov · Pull Request #289 · googleapis/proto-plus-python

This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Conversation

@software-dov

@software-dov software-dov commented Feb 4, 2022

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@software-dov
feat: add custom __dir__ for messages and message classes
ab94801
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().
@software-dov
software-dov requested review from a team, atulep, busunkim96, parthea and tswast February 4, 2022 23:16
@codecov

codecov Bot commented Feb 4, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

busunkim96
busunkim96 approved these changes Feb 7, 2022
View reviewed changes
Comment thread proto/message.py
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()))

@busunkim96 busunkim96 Feb 7, 2022

Copy link
Copy Markdown
Contributor

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@software-dov software-dov Feb 7, 2022

Copy link
Copy Markdown
Contributor Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@software-dov
Merge branch 'main' into custom-dir
84868af
@software-dov
software-dov merged commit 35e019e into googleapis:main Feb 7, 2022
@release-please release-please Bot mentioned this pull request Feb 7, 2022
chore(main): release 1.20.0 #292
Merged
gcf-merge-on-green Bot pushed a commit that referenced this pull request Feb 7, 2022
@release-please
chore(main): release 1.20.0 (#292)
2dad3d3
🤖 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).
parthea pushed a commit to googleapis/google-cloud-python that referenced this pull request Nov 24, 2025
@release-please
chore(main): release 1.20.0 (#292)
d90c5a0
🤖 I have created a release *beep* *boop*
---


## [1.20.0](googleapis/proto-plus-python@v1.19.9...v1.20.0) (2022-02-07)


### Features

* add custom __dir__ for messages and message classes ([#289](googleapis/proto-plus-python#289)) ([35e019e](googleapis/proto-plus-python@35e019e))


### Bug Fixes

* workaround for buggy pytest ([#291](googleapis/proto-plus-python#291)) ([28aa3b2](googleapis/proto-plus-python@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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@tswast tswast Awaiting requested review from tswast
@parthea parthea Awaiting requested review from parthea
@atulep atulep Awaiting requested review from atulep
1 more reviewer
@busunkim96 busunkim96 busunkim96 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@software-dov @busunkim96
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.