Skip to content

Commit a48c39f

Browse files
authored
fix: fix 'Couldn't build proto file' when using Python 3.13 (#492)
* 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
1 parent e5e8533 commit a48c39f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

proto/enums.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ def __new__(mcls, name, bases, attrs):
7373
(
7474
descriptor_pb2.EnumValueDescriptorProto(name=name, number=number)
7575
# Minor hack to get all the enum variants out.
76+
# Use the `_member_names` property to get only the enum members
77+
# See https://github.com/googleapis/proto-plus-python/issues/490
7678
for name, number in attrs.items()
77-
if isinstance(number, int)
79+
if name in attrs._member_names and isinstance(number, int)
7880
),
7981
key=lambda v: v.number,
8082
),

tests/clam.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
manifest={
2020
"Clam",
2121
"Species",
22+
"Color",
2223
},
2324
)
2425

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

3233

34+
class Color(proto.Enum):
35+
COLOR_UNKNOWN = 0
36+
BLUE = 1
37+
ORANGE = 2
38+
GREEN = 3
39+
40+
3341
class Clam(proto.Message):
3442
species = proto.Field(proto.ENUM, number=1, enum="Species")
3543
mass_kg = proto.Field(proto.DOUBLE, number=2)
44+
color = proto.Field(proto.ENUM, number=3, enum="Color")

0 commit comments

Comments
 (0)