Skip to content

Accessing Enum name by str() #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GalBezalel-RecoLabs opened this issue Nov 28, 2021 · 1 comment · Fixed by #293
Closed

Accessing Enum name by str() #291

GalBezalel-RecoLabs opened this issue Nov 28, 2021 · 1 comment · Fixed by #293
Labels
enhancement New feature or request

Comments

@GalBezalel-RecoLabs
Copy link

Say I've compiled:
class Priority(betterproto.Enum):
PRIORITY_LOW = 0
PRIORITY_MEDIUM = 1
PRIORITY_HIGH = 2

Accessing the string value of each instance (which is defined by .toString()) is done similarly to Enum class in python, via Priority.PRIORITY_LOW.name, for example.

From usability point of view, I'd like to access this by the pythonic convention of str(Priority.PRIORITY_LOW). (i.e. add __str__ method to the compiled class).

Appreciate your consideration.

@Gobot1234
Copy link
Collaborator

Gobot1234 commented Nov 28, 2021

Currently betterproto.Enum does already have a dunder str method which is just inherited from enum.Enum. With the 3.11(??) changes to the value of an enum's str I think this change makes sense an should be fine to include in 2.0.0 and my Enum branch along with a new repr method.

@Gobot1234 Gobot1234 added the enhancement New feature or request label Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants