From 25ab8ce6ae0d9f2f0955708944bfba99c997d5a4 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 15 Oct 2024 14:04:46 +0000 Subject: [PATCH 1/3] fix: fix 'Couldn't build proto file' when using Python 3.13 --- tests/clam.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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") From 3099991c756fd875024f06b1a043a1843596bf18 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 15 Oct 2024 14:20:30 +0000 Subject: [PATCH 2/3] fix: fix 'Couldn't build proto file' when using Python 3.13 --- proto/enums.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/enums.py b/proto/enums.py index 6207ad7d..769b6d83 100644 --- a/proto/enums.py +++ b/proto/enums.py @@ -74,7 +74,7 @@ def __new__(mcls, name, bases, attrs): descriptor_pb2.EnumValueDescriptorProto(name=name, number=number) # Minor hack to get all the enum variants out. 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, ), From d72dfb431c6e529c234677c3d0fcf1ea6afc3404 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 15 Oct 2024 16:04:12 +0000 Subject: [PATCH 3/3] add comment --- proto/enums.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/proto/enums.py b/proto/enums.py index 769b6d83..4073c2a3 100644 --- a/proto/enums.py +++ b/proto/enums.py @@ -73,6 +73,8 @@ 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 name in attrs._member_names and isinstance(number, int) ),