Skip to content

Enum values not defined in enum class #6028

Closed
@plannigan

Description

@plannigan

The documentation for enum says:

For example, you can access the values in the three following ways for the following enum in a proto:

enum SomeEnum {
    VALUE_A = 0;
    VALUE_B = 5;
    VALUE_C = 1234;
}
value-a = myproto_pb2.SomeEnum.VALUE_A
# or
myproto_pb2.VALUE_A
# or
myproto_pb2.SomeEnum.Value('VALUE_A')

But value-a = myproto_pb2.SomeEnum.VALUE_A fails.

What version of protobuf and what language are you using?
Version: v3.7.1/v3.6.1
Language: Python

What operating system (Linux, Windows, ...) and version?
Xubuntu 18.04

What runtime / compiler are you using (e.g., python version or gcc version)
gcc

What did you do?

  1. Save the proto definition from the documentation to a file name myproto.proto.
  2. Generate the python code:
./protoc --python_out=. --proto_path=. myproto.proto 
  1. Attempt to access the value in the ways the documentation demonstrates.
python -c "import myproto_pb2; print(myproto_pb2.SomeEnum.Value('VALUE_A')); print(myproto_pb2.VALUE_A); print(myproto_pb2.SomeEnum.VALUE_A);"

What did you expect to see

0
0
0

What did you see instead?

0
0
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'EnumTypeWrapper' object has no attribute 'VALUE_A'

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions