Thrift Python 客户端中具有默认值的默认参数 [英] Default arguments with default values in Thrift Python client
问题描述
我让 Python 客户端使用一些可选参数调用 Thrift 服务,如下所示:
I have Python client calls a Thrift service with some optional parameters like this:
bool postTweet(1: required Tweet tweet, 2: i32 x = 100);
如果我尝试从 Python 客户端调用此服务而不传递可选参数 x,则会出现异常:
If I tried to call this service from Python client without passing the optional parameter x, I get an exception:
TypeError: postTweet() takes exactly 2 arguments (1 given)
任何线索为什么我会收到此异常,但它是具有默认值的可选参数?
Any clues why I get this exception however it is optional parameter with a default value?
推荐答案
不能用默认值定义 thrift 函数(至少从我阅读 thrift 白皮书后的理解)
It's not possible to define a thrift function with default value (well at least from my understanding after reading the thrift whitepaper)
你可以做的是定义一个特殊的参数结构,让你省略一些字段.
What you can do, is to define a special parameter struct that let you omit some of the fields.
示例节俭代码:
struct PostTweetParameter {
1: required Tweet tweet;
2: optional i32 x;
}
bool postTweet(1: PostTweetParameter param);
然后你可以构造PostTweetParameter
,省略字段x
.
Then you can construct the PostTweetParameter
with field x
omitted.
这篇关于Thrift Python 客户端中具有默认值的默认参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!