8000 Handle rest of decorators too, re #410 · alex-python/fabric@6bf50c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6bf50c7

Browse files
committed
Handle rest of decorators too, re fabric#410
1 parent f38e3f1 commit 6bf50c7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

fabric/decorators.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def wrapper(func):
3434

3535
return wrapper if invoked else wrapper(func)
3636

37+
def _wrap_as_new(original, new):
38+
if isinstance(original, tasks.Task):
39+
return tasks.WrappedCallableTask(new)
40+
return new
41+
3742

3843
def _list_annotating_decorator(attribute, *values):
3944
def attach_list(func):
@@ -47,8 +52,7 @@ def inner_decorator(*args, **kwargs):
4752
setattr(inner_decorator, attribute, list(_values))
4853
# Don't replace @task new-style task objects with inner_decorator by
4954
# itself -- wrap in a new Task object first.
50-
if isinstance(func, tasks.Task):
51-
inner_decorator = tasks.WrappedCallableTask(inner_decorator)
55+
inner_decorator = _wrap_as_new(func, inner_decorator)
5256
return inner_decorator
5357
return attach_list
5458

@@ -133,6 +137,7 @@ def decorated(*args, **kwargs):
133137
if not hasattr(decorated, 'return_value'):
134138
decorated.return_value = func(*args, **kwargs)
135139
return decorated.return_value
140+
decorated = _wrap_as_new(func, decorated)
136141
# Mark as serial (disables parallelism) and return
137142
return serial(decorated)
138143

@@ -150,7 +155,7 @@ def serial(func):
150155
"""
151156
if not getattr(func, 'parallel', False):
152157
func.serial = True
153-
return func
158+
return _wrap_as_new(func, func)
154159

155160

156161
def parallel(pool_size=None):
@@ -174,7 +179,7 @@ def inner(*args, **kwargs):
174179
inner.parallel = True
175180
inner.serial = False
176181
inner.pool_size = pool_size
177-
return inner
182+
return _wrap_as_new(func, inner)
178183

179184
# Allow non-factory-style decorator use (@decorator vs @decorator())
180185
if type(pool_size) == type(real_decorator):
@@ -206,5 +211,5 @@ def outer(func):
206211
def inner(*args, **kwargs):
207212
with settings(**kw_settings):
208213
return func(*args, **kwargs)
209-
return inner
214+
return _wrap_as_new(func, inner)
210215
return outer

0 commit comments

Comments
 (0)
0