MCPcopy Create free account
hub / github.com/celery/celery / wrapper

Function wrapper

celery/app/base.py:225–254  ·  view source on GitHub ↗
(*task_args, **task_kwargs)

Source from the content-addressed store, hash-verified

223
224 @functools.wraps(task_fun)
225 def wrapper(*task_args, **task_kwargs):
226 # Validate task parameters if type hinted as BaseModel
227 bound_args = task_signature.bind(*task_args, **task_kwargs)
228 for arg_name, arg_value in bound_args.arguments.items():
229 arg_model = get_argument_model(arg_name, arg_value)
230 if arg_model is not None:
231 bound_args.arguments[arg_name] = validate_argument(arg_model, arg_value)
232
233 # Call the task with (potentially) converted arguments
234 returned_value = task_fun(*bound_args.args, **bound_args.kwargs)
235
236 # Dump Pydantic model if the returned value is an instance of pydantic.BaseModel *and* its
237 # class matches the typehint
238 if type_hints and 'return' in type_hints:
239 return_annotation = type_hints['return']
240 else:
241 return_annotation = task_signature.return_annotation
242
243 optional_return_annotation = get_optional_arg(return_annotation)
244 if optional_return_annotation is not None:
245 return_annotation = optional_return_annotation
246
247 if (
248 annotation_is_class(return_annotation)
249 and isinstance(returned_value, BaseModel)
250 and isinstance(returned_value, return_annotation)
251 ):
252 return returned_value.model_dump(**dump_kwargs)
253
254 return returned_value
255
256 # Parameters that positional and keyword arguments bind to. Other arguments
257 # go to *args or **kwargs, which the wrapper doesn't validate one by one.

Callers

nothing calls this directly

Calls 6

get_argument_modelFunction · 0.85
validate_argumentFunction · 0.85
get_optional_argFunction · 0.85
annotation_is_classFunction · 0.85
bindMethod · 0.80
itemsMethod · 0.45

Tested by

no test coverage detected