Thriftpy / thriftpy2

Pure python approach of Apache Thrift.
MIT License
572 stars 91 forks source link

Add enum constructor to create enum from value #111

Open aisk opened 4 years ago

aisk commented 4 years ago

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 commented 4 years ago

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

seidefrank commented 3 years ago

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 commented 1 year ago

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