Skip to content

Commit

Permalink
Refactor to move 'progress' argument check in submit_progress (#382)
Browse files Browse the repository at this point in the history
* Refactor to move 'progress' argument check in submit_progress

* Remove two more unnecessary .copy operations
  • Loading branch information
mdickinson committed Jul 8, 2021
1 parent 525fb31 commit 68ed49f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion traits_futures/background_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def background_task(self):
return CallBackgroundTask(
callable=self.callable,
args=self.args,
kwargs=self.kwargs.copy(),
kwargs=self.kwargs,
)


Expand Down
2 changes: 1 addition & 1 deletion traits_futures/background_iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def background_task(self):
return IterationBackgroundTask(
callable=self.callable,
args=self.args,
kwargs=self.kwargs.copy(),
kwargs=self.kwargs,
)


Expand Down
16 changes: 9 additions & 7 deletions traits_futures/background_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ def __init__(self, callable, args, kwargs):

def __call__(self, send, cancelled):
progress = ProgressReporter(send=send, cancelled=cancelled)
self.kwargs["progress"] = progress.report

try:
return self.callable(*self.args, **self.kwargs)
return self.callable(
*self.args,
**self.kwargs,
progress=progress.report,
)
except ProgressCancelled:
return None

Expand Down Expand Up @@ -148,13 +150,10 @@ def background_task(self):
callable can use ``send`` to send messages and ``cancelled`` to
check whether cancellation has been requested.
"""
if "progress" in self.kwargs:
raise TypeError("progress may not be passed as a named argument")

return ProgressBackgroundTask(
callable=self.callable,
args=self.args,
kwargs=self.kwargs.copy(),
kwargs=self.kwargs,
)


Expand Down Expand Up @@ -182,5 +181,8 @@ def submit_progress(executor, callable, *args, **kwargs):
future : ProgressFuture
Object representing the state of the background task.
"""
if "progress" in kwargs:
raise TypeError("progress may not be passed as a named argument")

task = BackgroundProgress(callable=callable, args=args, kwargs=kwargs)
return executor.submit(task)

0 comments on commit 68ed49f

Please sign in to comment.