@@ -185,17 +185,19 @@ def delay(self, *partial_args, **partial_kwargs):
185
185
"""Shortcut to :meth:`apply_async` using star arguments."""
186
186
return self .apply_async (partial_args , partial_kwargs )
187
187
188
- def apply (self , args = () , kwargs = {} , ** options ):
188
+ def apply (self , args = None , kwargs = None , ** options ):
189
189
"""Call task locally.
190
190
191
191
Same as :meth:`apply_async` but executed the task inline instead
192
192
of sending a task message.
193
193
"""
194
+ args = args if args else ()
195
+ kwargs = kwargs if kwargs else {}
194
196
# For callbacks: extra args are prepended to the stored args.
195
197
args , kwargs , options = self ._merge (args , kwargs , options )
196
198
return self .type .apply (args , kwargs , ** options )
197
199
198
- def apply_async (self , args = () , kwargs = {} , route_name = None , ** options ):
200
+ def apply_async (self , args = None , kwargs = None , route_name = None , ** options ):
199
201
"""Apply this task asynchronously.
200
202
201
203
Arguments:
@@ -210,6 +212,8 @@ def apply_async(self, args=(), kwargs={}, route_name=None, **options):
210
212
See also:
211
213
:meth:`[email protected] _async` and the :ref:`guide-calling` guide.
212
214
"""
215
+ args = args if args else ()
216
+ kwargs = kwargs if kwargs else {}
213
217
try :
214
218
_apply = self ._apply_async
215
219
except IndexError : # pragma: no cover
@@ -224,15 +228,18 @@ def apply_async(self, args=(), kwargs={}, route_name=None, **options):
224
228
# Borks on this, as it's a property
225
229
return _apply (args , kwargs , ** options )
226
230
227
- def _merge (self , args = (), kwargs = {}, options = {}, force = False ):
231
+ def _merge (self , args = None , kwargs = None , options = None , force = False ):
232
+ args = args if args else ()
233
+ kwargs = kwargs if kwargs else {}
234
+ options = options if options else {}
228
235
if self .immutable and not force :
229
236
return (self .args , self .kwargs ,
230
237
dict (self .options , ** options ) if options else self .options )
231
238
return (tuple (args ) + tuple (self .args ) if args else self .args ,
232
239
dict (self .kwargs , ** kwargs ) if kwargs else self .kwargs ,
233
240
dict (self .options , ** options ) if options else self .options )
234
241
235
- def clone (self , args = () , kwargs = {} , ** opts ):
242
+ def clone (self , args = None , kwargs = None , ** opts ):
236
243
"""Create a copy of this signature.
237
244
238
245
Arguments:
@@ -241,6 +248,8 @@ def clone(self, args=(), kwargs={}, **opts):
241
248
options (Dict): Partial options to be merged with
242
249
existing options.
243
250
"""
251
+ args = args if args else ()
252
+ kwargs = kwargs if kwargs else {}
244
253
# need to deepcopy options so origins links etc. is not modified.
245
254
if args or kwargs or opts :
246
255
args , kwargs , opts = self ._merge (args , kwargs , opts )
@@ -554,20 +563,24 @@ def unchain_tasks(self):
554
563
task .link_error (sig )
555
564
return tasks
556
565
557
- def apply_async (self , args = () , kwargs = {} , ** options ):
566
+ def apply_async (self , args = None , kwargs = None , ** options ):
558
567
# python is best at unpacking kwargs, so .run is here to do that.
568
+ args = args if args else ()
569
+ kwargs = kwargs if kwargs else []
559
570
app = self .app
560
571
if app .conf .task_always_eager :
561
572
with allow_join_result ():
562
573
return self .apply (args , kwargs , ** options )
563
574
return self .run (args , kwargs , app = app , ** (
564
575
dict (self .options , ** options ) if options else self .options ))
565
576
566
- def run (self , args = () , kwargs = {} , group_id = None , chord = None ,
577
+ def run (self , args = None , kwargs = None , group_id = None , chord = None ,
567
578
task_id = None , link = None , link_error = None , publisher = None ,
568
579
producer = None , root_id = None , parent_id = None , app = None , ** options ):
569
580
# pylint: disable=redefined-outer-name
570
581
# XXX chord is also a class in outer scope.
582
+ args = args if args else ()
583
+ kwargs = kwargs if kwargs else []
571
584
app = app or self .app
572
585
use_link = self ._use_link
573
586
if use_link is None and app .conf .task_protocol == 1 :
@@ -707,7 +720,9 @@ def prepare_steps(self, args, kwargs, tasks,
707
720
prev_res = node
708
721
return tasks , results
709
722
710
- def apply (self , args = (), kwargs = {}, ** options ):
723
+ def apply (self , args = None , kwargs = None , ** options ):
724
+ args = args if args else ()
725
+ kwargs = kwargs if kwargs else {}
711
726
last , (fargs , fkwargs ) = None , (args , kwargs )
712
727
for task in self .tasks :
713
728
res = task .clone (fargs , fkwargs ).apply (
@@ -808,8 +823,10 @@ def __init__(self, task, it, **options):
808
823
{'task' : task , 'it' : regen (it )}, immutable = True , ** options
809
824
)
810
825
811
- def apply_async (self , args = () , kwargs = {} , ** opts ):
826
+ def apply_async (self , args = None , kwargs = None , ** opts ):
812
827
# need to evaluate generators
828
+ args = args if args else ()
829
+ kwargs = kwargs if kwargs else {}
813
830
task , it = self ._unpack_args (self .kwargs )
814
831
return self .type .apply_async (
815
832
(), {'task' : task , 'it' : list (it )},
@@ -871,7 +888,9 @@ def __init__(self, task, it, n, **options):
871
888
def __call__ (self , ** options ):
872
889
return self .apply_async (** options )
873
890
874
- def apply_async (self , args = (), kwargs = {}, ** opts ):
891
+ def apply_async (self , args = None , kwargs = None , ** opts ):
892
+ args = args if args else ()
893
+ kwargs = kwargs if kwargs else {}
875
894
return self .group ().apply_async (
876
895
args , kwargs ,
877
896
route_name = task_name_from (self .kwargs .get ('task' )), ** opts
@@ -965,8 +984,9 @@ def skew(self, start=1.0, stop=None, step=1.0):
965
984
task .set (countdown = next (it ))
966
985
return self
967
986
968
- def apply_async (self , args = () , kwargs = None , add_to_parent = True ,
987
+ def apply_async (self , args = None , kwargs = None , add_to_parent = True ,
969
988
producer = None , link = None , link_error = None , ** options ):
989
+ args = args if args else ()
970
990
if link is not None :
971
991
raise TypeError ('Cannot add link to group: use a chord' )
972
992
if link_error is not None :
@@ -1000,7 +1020,9 @@ def apply_async(self, args=(), kwargs=None, add_to_parent=True,
1000
1020
parent_task .add_trail (result )
1001
1021
return result
1002
1022
1003
- def apply (self , args = (), kwargs = {}, ** options ):
1023
+ def apply (self , args = None , kwargs = None , ** options ):
1024
+ args = args if args else ()
1025
+ kwargs = kwargs if kwargs else {}
1004
1026
app = self .app
1005
1027
if not self .tasks :
1006
1028
return self .freeze () # empty group returns GroupResult
@@ -1184,7 +1206,9 @@ def _unpack_args(header=None, body=None, **kwargs):
1184
1206
return (header , body ), kwargs
1185
1207
1186
1208
def __init__ (self , header , body = None , task = 'celery.chord' ,
1187
- args = (), kwargs = {}, app = None , ** options ):
1209
+ args = None , kwargs = None , app = None , ** options ):
1210
+ args = args if args else ()
1211
+ kwargs = kwargs if kwargs else {}
1188
1212
Signature .__init__ (
1189
1213
self , task , args ,
1190
1214
{'kwargs' : kwargs , 'header' : _maybe_group (header , app ),
@@ -1220,10 +1244,11 @@ def freeze(self, _id=None, group_id=None, chord=None,
1220
1244
self .id = self .tasks .id
1221
1245
return bodyres
1222
1246
1223
- def apply_async (self , args = () , kwargs = {} , task_id = None ,
1247
+ def apply_async (self , args = None , kwargs = None , task_id = None ,
1224
1248
producer = None , publisher = None , connection = None ,
1225
1249
router = None , result_cls = None , ** options ):
1226
- kwargs = kwargs or {}
1250
+ args = args if args else ()
1251
+ kwargs = kwargs if kwargs else {}
1227
1252
args = (tuple (args ) + tuple (self .args )
1228
1253
if args and not self .immutable else self .args )
1229
1254
body = kwargs .pop ('body' , None ) or self .kwargs ['body' ]
@@ -1239,7 +1264,10 @@ def apply_async(self, args=(), kwargs={}, task_id=None,
1239
1264
# chord([A, B, ...], C)
1240
1265
return self .run (tasks , body , args , task_id = task_id , ** options )
1241
1266
1242
- def apply (self , args = (), kwargs = {}, propagate = True , body = None , ** options ):
1267
+ def apply (self , args = None , kwargs = None ,
1268
+ propagate = True , body = None , ** options ):
1269
+ args = args if args else ()
1270
+ kwargs = kwargs if kwargs else {}
1243
1271
body = self .body if body is None else body
1244
1272
tasks = (self .tasks .clone () if isinstance (self .tasks , group )
1245
1273
else group (self .tasks , app = self .app ))
0 commit comments