MCPcopy
hub / github.com/celery/celery / _merge

Method _merge

celery/canvas.py:402–442  ·  view source on GitHub ↗

Merge partial args/kwargs/options with existing ones. If the signature is immutable and ``force`` is False, the existing args/kwargs will be returned as-is and only the options will be merged. Stamped headers are considered immutable and will not be merged regardless.

(self, args=None, kwargs=None, options=None, force=False)

Source from the content-addressed store, hash-verified

400 return _apply(args, kwargs, **options)
401
402 def _merge(self, args=None, kwargs=None, options=None, force=False):
403 """Merge partial args/kwargs/options with existing ones.
404
405 If the signature is immutable and ``force`` is False, the existing
406 args/kwargs will be returned as-is and only the options will be merged.
407
408 Stamped headers are considered immutable and will not be merged regardless.
409
410 Arguments:
411 args (Tuple): Partial args to be prepended to the existing args.
412 kwargs (Dict): Partial kwargs to be merged with existing kwargs.
413 options (Dict): Partial options to be merged with existing options.
414 force (bool): If True, the args/kwargs will be merged even if the signature is
415 immutable. The stamped headers are not affected by this option and will not
416 be merged regardless.
417
418 Returns:
419 Tuple: (args, kwargs, options)
420 """
421 args = args if args else ()
422 kwargs = kwargs if kwargs else {}
423 if options is not None:
424 # We build a new options dictionary where values in `options`
425 # override values in `self.options` except for keys which are
426 # noted as being immutable (unrelated to signature immutability)
427 # implying that allowing their value to change would stall tasks
428 immutable_options = self._IMMUTABLE_OPTIONS
429 if "stamped_headers" in self.options:
430 immutable_options = self._IMMUTABLE_OPTIONS.union(set(self.options.get("stamped_headers", [])))
431 # merge self.options with options without overriding stamped headers from self.options
432 new_options = {**self.options, **{
433 k: v for k, v in options.items()
434 if k not in immutable_options or k not in self.options
435 }}
436 else:
437 new_options = self.options
438 if self.immutable and not force:
439 return (self.args, self.kwargs, new_options)
440 return (tuple(args) + tuple(self.args) if args else self.args,
441 dict(self.kwargs, **kwargs) if kwargs else self.kwargs,
442 new_options)
443
444 def clone(self, args=None, kwargs=None, **opts):
445 """Create a copy of this signature.

Callers 8

__call__Method · 0.95
applyMethod · 0.95
apply_asyncMethod · 0.95
cloneMethod · 0.95
reprcallMethod · 0.95
test_merge_immutableMethod · 0.80

Calls 2

getMethod · 0.45
itemsMethod · 0.45

Tested by 3

test_merge_immutableMethod · 0.64