Пример #1
0
 def add_annotations(f):
     # prepare the signature
     param_names, annotations = get_python_function_arguments(f)
     if annotations:
         raise ValueError('@Signature cannot be applied to functions that already have annotations')
     annotations = {}
     if len(args) + len(kwargs) != len(param_names):
         raise TypeError("{} annotations provided for function to be decorated, but function has {} parameters".format(len(args) + len(kwargs), len(param_names)))
     # implant anotations into f
     params_dict = { name: name for name in param_names }
     f.__annotations__ = map_function_arguments(param_names, params_dict, *args, **kwargs)
     return f # and return the updated function
Пример #2
0
 def add_annotations(f):
     # prepare the signature
     param_names, annotations = get_python_function_arguments(f)
     if annotations:
         raise ValueError('@Signature cannot be applied to functions that already have annotations')
     annotations = {}
     if len(args) + len(kwargs) != len(param_names):
         raise TypeError("{} annotations provided for function to be decorated, but function has {} parameters".format(len(args) + len(kwargs), len(param_names)))
     # implant anotations into f
     params_dict = { name: name for name in param_names }
     f.__annotations__ = map_function_arguments(param_names, params_dict, *args, **kwargs)
     return f # and return the updated function