Skip to content

Commit

Permalink
fix: fix 'Couldn't build proto file' when using Python 3.13 (#492)
Browse files Browse the repository at this point in the history
* fix: fix 'Couldn't build proto file' when using Python 3.13

* fix: fix 'Couldn't build proto file' when using Python 3.13

* add comment
  • Loading branch information
parthea authored Oct 15, 2024
1 parent e5e8533 commit a48c39f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion proto/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ def __new__(mcls, name, bases, attrs):
(
descriptor_pb2.EnumValueDescriptorProto(name=name, number=number)
# Minor hack to get all the enum variants out.
# Use the `_member_names` property to get only the enum members
# See https://github.com/googleapis/proto-plus-python/issues/490
for name, number in attrs.items()
if isinstance(number, int)
if name in attrs._member_names and isinstance(number, int)
),
key=lambda v: v.number,
),
Expand Down
9 changes: 9 additions & 0 deletions tests/clam.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
manifest={
"Clam",
"Species",
"Color",
},
)

Expand All @@ -30,6 +31,14 @@ class Species(proto.Enum):
GIGAS = 3


class Color(proto.Enum):
COLOR_UNKNOWN = 0
BLUE = 1
ORANGE = 2
GREEN = 3


class Clam(proto.Message):
species = proto.Field(proto.ENUM, number=1, enum="Species")
mass_kg = proto.Field(proto.DOUBLE, number=2)
color = proto.Field(proto.ENUM, number=3, enum="Color")

0 comments on commit a48c39f

Please sign in to comment.