2019-11-13 16:15:54 +00:00
|
|
|
def get_argument_annotations(func):
|
|
|
|
return list(value for key, value in func.__annotations__.items() if key !=
|
|
|
|
'return')
|
|
|
|
|
|
|
|
def get_return_annotations(func):
|
|
|
|
return func.__annotations__['return']
|
|
|
|
|
2019-07-05 14:26:25 +00:00
|
|
|
def complitable_functions(output_function, input_function, convert_table):
|
2019-11-13 16:15:54 +00:00
|
|
|
input_keys = set(get_argument_annotations(input_function))
|
|
|
|
return_keys = set(get_return_annotations(output_function))
|
2019-07-05 14:26:25 +00:00
|
|
|
all_possible_return_keys = return_keys.union(
|
|
|
|
convert_table.all_possible_conversions(return_keys)
|
|
|
|
)
|
|
|
|
print("return:%s\npossible_output:%s" % (return_keys,
|
|
|
|
all_possible_return_keys))
|
|
|
|
return input_keys.issubset(all_possible_return_keys)
|
|
|
|
|
|
|
|
def get_converted_arguments(function, simple_arg_dict, convert_table):
|
2019-11-13 16:15:54 +00:00
|
|
|
#This function returns list of arguments needed by function made from
|
|
|
|
#simple_arg_dict by convert_table
|
2019-07-05 14:26:25 +00:00
|
|
|
if simple_arg_dict == None:
|
|
|
|
return [None for key in function.__annotations__.keys() if key != 'return']
|
|
|
|
result = []
|
2019-11-13 16:15:54 +00:00
|
|
|
if not hasattr(function, "__annotations__"):
|
|
|
|
return result
|
2019-07-05 14:26:25 +00:00
|
|
|
for key, value in function.__annotations__.items():
|
|
|
|
if key != 'return':
|
|
|
|
converted_arg = None
|
|
|
|
try:
|
|
|
|
converted_arg = simple_arg_dict[value]
|
|
|
|
except KeyError:
|
|
|
|
key_to_convert, convert_function = convert_table.get_converter(
|
|
|
|
simple_arg_dict.keys(),
|
|
|
|
value
|
|
|
|
)
|
|
|
|
key_to_convert = list(key_to_convert)[0]
|
|
|
|
converted_arg = convert_function(
|
|
|
|
simple_arg_dict[key_to_convert]
|
|
|
|
)[value]
|
|
|
|
result.append(converted_arg)
|
|
|
|
return result
|