@@ -246,11 +246,6 @@ def create_function(func_signature, # type: Union[str, Signature]
246246 if isinstance (func_signature , str ):
247247 # transform the string into a Signature and make sure the string contains ":"
248248 func_name_from_str , func_signature , func_signature_str = get_signature_from_string (func_signature , evaldict )
249- # If the signature is specified as a string, `__signature__` will not be correct in this case, since it
250- # will be a string. If it was computed in some other fashion (i.e. is an instance of inspect.Signature),
251- # then there is no need to update it.
252- if '__signature__' in attrs :
253- attrs ['__signature__' ] = func_signature
254249
255250 # if not explicitly overridden using `func_name`, the name in the string takes over
256251 if func_name_from_str is not None :
@@ -283,6 +278,11 @@ def create_function(func_signature, # type: Union[str, Signature]
283278 else :
284279 raise TypeError ("Invalid type for `func_signature`: %s" % type (func_signature ))
285280
281+ if isinstance (attrs .get ('__signature__' ), str ):
282+ # __signature__ must be a Signature object, so if it is a string,
283+ # we need to evaluate it.
284+ attrs ['__signature__' ] = get_signature_from_string (attrs ['__signature__' ], evaldict )[1 ]
285+
286286 # extract all information needed from the `Signature`
287287 params_to_kw_assignment_mode = get_signature_params (func_signature )
288288 params_names = list (params_to_kw_assignment_mode .keys ())
0 commit comments