Open lockeliu opened 1 month ago
async
is a keyword in Python, so we can't generate a Python class with this field name. But maybe we can improve the error message for better explanation.
async
is a keyword in Python, so we can't generate a Python class with this field name. But maybe we can improve the error message for better explanation.
If I put the test structure before Template, will it succeed again? For example `namespace go test.test.test namespace py cg
struct Test { 1: required string name }
struct Template { 1: optional string async 2: optional Test test
}
`
Is there any way to solve this problem without changing the field name?
We can load the thrift file in the second case, but the loaded types are still incomplete, it wouldn't work as you expected. We should raise an error in this case.
For your specified scenario, you can change the field name async
to another one. The Thrift protocol only uses position as the field name, so it's okay to use a different field name between the servers and clients.
Got it, thanks.
Are there any other python keywords that cannot be generated?
Any keyword should not be used here.
我的thrift 文件如下: `namespace go test.test.test namespace py cg
struct Template { 1: optional string async 2: optional Test test
}
struct Test { 1: required string name } `
main函数如下:
`import os import sys import thriftpy2
if name == "main": thriftpy2.parser.lexer.thrift_reserved_keywords = [] IDL_PATH="./test.thrift" res = thriftpy2.load(IDL_PATH, module_name="cg_thrift")`
失败信息如下:
thriftpy2.parser.exc.ThriftParserError: No type found: 'Test', at line 6
如果把thrift 里面的 async 字段去掉就成功了