diff options
author | Adrian Herrmann <adrian.herrmann@qt.io> | 2024-04-23 17:23:40 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-04-24 14:14:49 +0000 |
commit | 40db87449d69e0942ef62d9ed4dec0f6374e44f9 (patch) | |
tree | 570691675032458335337ba05945ab56b46ad973 | |
parent | 47d4d01acbf65ca901c46b52dad3221a682067b5 (diff) |
QtAsyncio: Improve readability of _step
Improve the readability of the QAsyncioTask._step function; avoid nested
try/except blocks.
Task-number: PYSIDE-769
Change-Id: Ibb82c50cf93b084b30dd2a5abcc0197ae25802e0
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
(cherry picked from commit 29136f0186d5f281f751c8974ae888913e5d765a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | sources/pyside6/PySide6/QtAsyncio/tasks.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/sources/pyside6/PySide6/QtAsyncio/tasks.py b/sources/pyside6/PySide6/QtAsyncio/tasks.py index 6777b8bc3..c04006686 100644 --- a/sources/pyside6/PySide6/QtAsyncio/tasks.py +++ b/sources/pyside6/PySide6/QtAsyncio/tasks.py @@ -64,19 +64,18 @@ class QAsyncioTask(futures.QAsyncioFuture): result = None self._future_to_await = None + if asyncio.futures.isfuture(exception_or_future): + try: + exception_or_future.result() + except BaseException as e: + exception_or_future = e + try: asyncio._enter_task(self._loop, self) # type: ignore[arg-type] - if exception_or_future is None: - result = self._coro.send(None) - elif asyncio.futures.isfuture(exception_or_future): - try: - exception_or_future.result() - except BaseException as e: - result = self._coro.throw(e) - else: - result = self._coro.send(None) - elif isinstance(exception_or_future, BaseException): + if isinstance(exception_or_future, BaseException): result = self._coro.throw(exception_or_future) + else: + result = self._coro.send(None) except StopIteration as e: self._state = futures.QAsyncioFuture.FutureState.DONE_WITH_RESULT self._result = e.value |