thriftpy2 icon indicating copy to clipboard operation
thriftpy2 copied to clipboard

Add enum constructor to create enum from value

Open aisk opened this issue 5 years ago • 3 comments

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?

aisk avatar Dec 31 '19 10:12 aisk

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

ethe avatar Jan 01 '20 05:01 ethe

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!

seidefrank avatar Nov 10 '20 00:11 seidefrank

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

truebit avatar Feb 22 '23 12:02 truebit