diff --git a/proto/enums.py b/proto/enums.py index 6207ad7..4073c2a 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 4946ebe..2f9dde1 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")