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

fix: dir(proto.Message) does not raise #302

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions proto/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,25 +274,28 @@ def meta(cls):
return cls._meta

def __dir__(self):
names = set(dir(type))
names.update(
(
"meta",
"pb",
"wrap",
"serialize",
"deserialize",
"to_json",
"from_json",
"to_dict",
"copy_from",
try:
names = set(dir(type))
names.update(
(
"meta",
"pb",
"wrap",
"serialize",
"deserialize",
"to_json",
"from_json",
"to_dict",
"copy_from",
)
)
)
desc = self.pb().DESCRIPTOR
names.update(t.name for t in desc.nested_types)
names.update(e.name for e in desc.enum_types)
desc = self.pb().DESCRIPTOR
names.update(t.name for t in desc.nested_types)
names.update(e.name for e in desc.enum_types)

return names
return names
except AttributeError:
return dir(type)

def pb(cls, obj=None, *, coerce: bool = False):
"""Return the underlying protobuf Message class or instance.
Expand Down
4 changes: 4 additions & 0 deletions tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,7 @@ class Arm(proto.Message):

actual = set(dir(Mollusc))
assert actual == expected


def test_dir_message_base():
assert set(dir(proto.Message)) == set(dir(type))