[Mod] flake8 code quality improvement

This commit is contained in:
vn.py 2019-09-03 10:20:36 +08:00
parent 65e71ae66d
commit 3aab7b13db
9 changed files with 30 additions and 23 deletions

View File

@ -730,4 +730,3 @@ CFutureRspStrategyDetailField = {
"SafeDeep": "int",
"MainRange": "int",
}

View File

@ -117,4 +117,3 @@ CMarketRspTradeDateField = {
"TradeDate": "string",
"TradeProduct": "string",
}

View File

@ -607,4 +607,3 @@ CStockReqVerifyCodeField = {
"VerifyCode": "string",
"ErrorDescription": "string",
}

View File

@ -53,7 +53,7 @@ class ApiGenerator:
line = line.replace("\n", "")
line = line.replace("\t", "")
line = line.replace("{}", "")
if "virtual void On" in line:
self.process_callback(line)
elif "virtual bool Req" in line:
@ -130,7 +130,8 @@ class ApiGenerator:
line = self.lines[name]
on_name = name.replace("On", "on")
f.write(line.replace("virtual void ", f"void {self.class_name}::") + "\n")
f.write(line.replace("virtual void ",
f"void {self.class_name}::") + "\n")
f.write("{\n")
f.write("\tgil_scoped_acquire acquire;\n")
@ -149,13 +150,15 @@ class ApiGenerator:
f.write("\tdict error;\n")
f.write("\tif (pRspInfo)\n")
f.write("\t{\n")
struct_fields = self.structs[type_]
for struct_field, struct_type in struct_fields.items():
if struct_type == "string":
f.write(f"\t\terror[\"{struct_field}\"] = toUtf({field}->{struct_field});\n")
f.write(
f"\t\terror[\"{struct_field}\"] = toUtf({field}->{struct_field});\n")
else:
f.write(f"\t\terror[\"{struct_field}\"] = {field}->{struct_field};\n")
f.write(
f"\t\terror[\"{struct_field}\"] = {field}->{struct_field};\n")
f.write("\t}\n")
else:
@ -164,13 +167,15 @@ class ApiGenerator:
f.write("\tdict data;\n")
f.write(f"\tif ({field})\n")
f.write("\t{\n")
struct_fields = self.structs[type_]
for struct_field, struct_type in struct_fields.items():
if struct_type == "string":
f.write(f"\t\tdata[\"{struct_field}\"] = toUtf({field}->{struct_field});\n")
f.write(
f"\t\tdata[\"{struct_field}\"] = toUtf({field}->{struct_field});\n")
else:
f.write(f"\t\tdata[\"{struct_field}\"] = {field}->{struct_field};\n")
f.write(
f"\t\tdata[\"{struct_field}\"] = {field}->{struct_field};\n")
f.write("\t}\n")
@ -260,11 +265,14 @@ class ApiGenerator:
if __name__ == "__main__":
market_generator = ApiGenerator("../include/da/DAMarketApi.h", "da", "market", "MarketApi")
market_generator = ApiGenerator(
"../include/da/DAMarketApi.h", "da", "market", "MarketApi")
market_generator.run()
future_generator = ApiGenerator("../include/da/DAFutureApi.h", "da", "future", "FutureApi")
future_generator = ApiGenerator(
"../include/da/DAFutureApi.h", "da", "future", "FutureApi")
future_generator.run()
stock_generator = ApiGenerator("../include/da/DAStockApi.h", "da", "stock", "StockApi")
stock_generator = ApiGenerator(
"../include/da/DAStockApi.h", "da", "stock", "StockApi")
stock_generator.run()

View File

@ -41,7 +41,7 @@ class DataTypeGenerator:
self.process_define(line)
elif line.startswith("typedef"):
self.process_typedef(line)
def process_define(self, line: str):
"""处理常量定义"""
words = line.split(" ")
@ -62,7 +62,7 @@ class DataTypeGenerator:
"""处理类型定义"""
words = line.split(" ")
words = [word for word in words if word]
name = words[2]
typedef = TYPE_CPP2PY[words[1]]

View File

@ -60,7 +60,7 @@ class StructGenerator:
value = words[2]
new_line = f"{value} = {name}\n\n"
self.f_struct.write(new_line)
def process_declare(self, line: str):
"""处理声明"""
words = line.split(" ")
@ -91,11 +91,14 @@ class StructGenerator:
if __name__ == "__main__":
generator_future = StructGenerator("../include/da/DAFutureStruct.h", "da", "future")
generator_future = StructGenerator(
"../include/da/DAFutureStruct.h", "da", "future")
generator_future.run()
generator_stock = StructGenerator("../include/da/DAStockStruct.h", "da", "stock")
generator_stock = StructGenerator(
"../include/da/DAStockStruct.h", "da", "stock")
generator_stock.run()
generator_market = StructGenerator("../include/da/DAMarketStruct.h", "da", "market")
generator_market = StructGenerator(
"../include/da/DAMarketStruct.h", "da", "market")
generator_market.run()

View File

@ -4909,4 +4909,3 @@ CThostFtdcDepartmentUserField = {
CThostFtdcQueryFreqField = {
"QueryFreq": "int",
}

View File

@ -444,7 +444,7 @@ class DaFutureApi(FutureApi):
symbol_name_map[contract.vt_symbol] = contract.name
symbol_currency_map[contract.symbol] = data["CommodityFCurrencyNo"]
self.gateway.on_contract(contract)
if last:

View File

@ -359,7 +359,7 @@ class OkexsRestApi(RestClient):
""""""
for data in datas:
holdings = data['holding']
for holding in holdings:
symbol = holding["instrument_id"].upper()
pos = _parse_position_holding(holding, symbol=symbol,