protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

EnumTypeWrapper objects should be usable according to the enum.Enum interface (or maybe the enum.IntEnum interface)

Open nathanielmanistaatgoogle opened this issue 6 years ago • 6 comments

To what language does this apply? Python.

Describe the problem you are trying to solve. The Python language (since 3.4) has an enum module, but the generated Python classes in _pb2 files don't behave according to the interfaces of the classes defined in the enum module.

Describe the solution you'd like I think EnumTypeWrapper objects should support being used, as much as possible, as though they were subclasses of enum.Enum.

Describe alternatives you've considered enum.IntEnum, though disfavored in new code, exists to allow int-based ad hoc "enums" from before Python 3.4 to be upgraded to be usable according to the interface of enum.Enum. It may have a role to play.

Additional context This would be really great for type-checking; it would allow authors to describe parameters and return values as of type my_module_pb2.MyEnum rather than as of type int.

See https://github.com/protocolbuffers/protobuf/pull/5234, where I asked whether the EnumTypeWrapper classes can be replaced by enum from the stdlib.

twmr avatar Aug 19 '19 17:08 twmr

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

github-actions[bot] avatar May 12 '24 10:05 github-actions[bot]

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

Yes, this issue still tracks a fantastic opportunity for improvement in Protocol Buffers Python.

I would like to take this on if it's still unassigned.

AlexeyGy avatar Jul 12 '24 12:07 AlexeyGy

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.

github-actions[bot] avatar Oct 11 '24 10:10 github-actions[bot]

Still a valid, not-yet-implemented improvement suggestion, Mr. Robot.

cvrebert avatar Oct 12 '24 01:10 cvrebert