Skip to content
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

Add enum constructor to create enum from value #111

Open
aisk opened this issue Dec 31, 2019 · 3 comments
Open

Add enum constructor to create enum from value #111

aisk opened this issue Dec 31, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@aisk
Copy link
Member

aisk commented Dec 31, 2019

Thought we have a thrift file:

enum TestEnum {
    a = 1;
    b = 2;
}

It's common to create a enum from it's value like this:

a = TestEnum(1)

For now, the enum type do not accept any constructor parameters, can we add it like above, or generated a public api to do this convert?

@ethe
Copy link
Member

ethe commented Jan 1, 2020

Yes, I think it is better to have the same behavior as https://docs.python.org/3/library/enum.html

@ethe ethe added the enhancement New feature or request label Jan 21, 2020
@seidefrank
Copy link

Is there a workaround? I need to use an API that, per .pyi file, expects an enum type, but I am only given an integer value. Is it possible to convert the int value to an instance of the Thrift-generated enum type? Thanks!

@truebit
Copy link
Contributor

truebit commented Feb 22, 2023

+1
Now thriftpy2 just treats thrift enum type to TType.I32.
I think we need to add a new TType ENUM.

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

No branches or pull requests

4 participants