commit: 71c59145e0c7b631ec3f41e0d711445786d16f8f Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Thu Mar 15 02:45:31 2018 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Thu Mar 15 02:49:02 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=71c59145
portage.util.futures.wait: fix arguments for asyncio compat The bare "*" is not supported in python2.7, and in python3 the bare "*" means that keyword arguments must be used for the arguments that follow. Fixes: e43f6c583ed9 ("Add iter_completed convenience function (bug 648790)") pym/portage/util/futures/iter_completed.py | 2 +- pym/portage/util/futures/wait.py | 16 +++------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/pym/portage/util/futures/iter_completed.py b/pym/portage/util/futures/iter_completed.py index 1050b6fa7..ad6275b49 100644 --- a/pym/portage/util/futures/iter_completed.py +++ b/pym/portage/util/futures/iter_completed.py @@ -52,7 +52,7 @@ def iter_completed(futures, max_jobs=None, max_load=None, loop=None): # task_generator is exhausted while future_map: done, pending = loop.run_until_complete( - wait(*list(future_map.values()), return_when=FIRST_COMPLETED)) + wait(list(future_map.values()), return_when=FIRST_COMPLETED)) for future in done: del future_map[id(future)] yield future diff --git a/pym/portage/util/futures/wait.py b/pym/portage/util/futures/wait.py index 3f0bdbff5..bd85bb053 100644 --- a/pym/portage/util/futures/wait.py +++ b/pym/portage/util/futures/wait.py @@ -11,15 +11,13 @@ except ImportError: from portage.util._eventloop.global_event_loop import global_event_loop -# Use **kwargs since python2.7 does not allow arguments with defaults -# to follow *futures. -def wait(*futures, **kwargs): +def wait(futures, loop=None, timeout=None, return_when=ALL_COMPLETED): """ Use portage's internal EventLoop to emulate asyncio.wait: https://docs.python.org/3/library/asyncio-task.html#asyncio.wait - @param future: future to wait for - @type future: asyncio.Future (or compatible) + @param futures: futures to wait for + @type futures: asyncio.Future (or compatible) @param timeout: number of seconds to wait (wait indefinitely if not specified) @type timeout: int or float @@ -32,14 +30,6 @@ def wait(*futures, **kwargs): @return: tuple of (done, pending). @rtype: asyncio.Future (or compatible) """ - if not futures: - raise TypeError("wait() missing 1 required positional argument: 'future'") - loop = kwargs.pop('loop', None) - timeout = kwargs.pop('timeout', None) - return_when = kwargs.pop('return_when', ALL_COMPLETED) - if kwargs: - raise TypeError("wait() got an unexpected keyword argument '{}'".\ - format(next(iter(kwargs)))) loop = loop or global_event_loop() result_future = loop.create_future() _Waiter(futures, timeout, return_when, result_future, loop)