thriftpy2
thriftpy2 copied to clipboard
Add enum constructor to create enum from value
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?
Yes, I think it is better to have the same behavior as https://docs.python.org/3/library/enum.html
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!
+1 Now thriftpy2 just treats thrift enum type to TType.I32. I think we need to add a new TType ENUM.