请需要您的帮助。我有以下方法:
zip
本质上def edit_data(self, **kwargs: dict) -> bool:
func_map = {
'supID': self.po_xml.change_supplier_id,
'uniID': self.po_xml.change_university_id,
'creds': self.po_xml.change_sender_credentials,
'billAdd': self.po_xml.change_bill_address,
'shipAdd': self.po_xml.change_ship_address,
'conAdd': self.po_xml.change_contact_address,
'lineItems': self.po_xml.change_line_items,
'ordNo': self.po_xml.change_order_number,
}
try:
dict_only = ['billAdd', 'shipAdd', 'conAdd', ]
for key, value in kwargs.items():
# run the function for that key
if key not in func_map.keys():
raise LookupError(f'Error in {key}, not a valid function')
if type(value) == dict and \
key not in dict_only and \
not func_map[key](**value):
raise LookupError(
'Something went wrong, check your variables.')
elif key in dict_only and \
not func_map[key](value):
raise LookupError(
'Something went wrong, check your variables.')
elif type(value) in [str, list] and \
not func_map[key](value):
raise LookupError(
'Somethin went wrong, check your variable')
return True
except LookupError as ie:
log.error(ie)
return False
接收几种类型的输入(即str,list,dict),如果所有输入都成功,则返回True。上面定义的所有函数如果更新失败均返回False,从而触发edit_data
。
我知道有一种方法可以进一步降低其复杂性,但是我不太熟悉该如何做。我应该知道有什么LookupError
魔术可以帮助您吗?