From a48c39ff2212261bc932d10132086a6c55be22e9 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 15 Oct 2024 12:47:49 -0400 Subject: [PATCH] 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 --- proto/enums.py | 4 +++- tests/clam.py | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/proto/enums.py b/proto/enums.py index 6207ad7d..4073c2a3 100644 --- a/proto/enums.py +++ b/proto/enums.py @@ -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, ), diff --git a/tests/clam.py b/tests/clam.py index 4946ebe1..2f9dde13 100644 --- a/tests/clam.py +++ b/tests/clam.py @@ -19,6 +19,7 @@ manifest={ "Clam", "Species", + "Color", }, ) @@ -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")