diff options
Diffstat (limited to 'sources/pyside6/PySide6')
| -rw-r--r-- | sources/pyside6/PySide6/QtAsyncio/futures.py | 2 | ||||
| -rw-r--r-- | sources/pyside6/PySide6/QtAsyncio/tasks.py | 23 |
2 files changed, 14 insertions, 11 deletions
diff --git a/sources/pyside6/PySide6/QtAsyncio/futures.py b/sources/pyside6/PySide6/QtAsyncio/futures.py index e1bcd86fc..580f34db6 100644 --- a/sources/pyside6/PySide6/QtAsyncio/futures.py +++ b/sources/pyside6/PySide6/QtAsyncio/futures.py @@ -37,7 +37,7 @@ class QAsyncioFuture(): self._callbacks: typing.List[typing.Callable] = list() - self._cancel_message = None + self._cancel_message: typing.Optional[str] = None def __await__(self): if not self.done(): diff --git a/sources/pyside6/PySide6/QtAsyncio/tasks.py b/sources/pyside6/PySide6/QtAsyncio/tasks.py index 7bca955b0..027615f21 100644 --- a/sources/pyside6/PySide6/QtAsyncio/tasks.py +++ b/sources/pyside6/PySide6/QtAsyncio/tasks.py @@ -62,7 +62,7 @@ class QAsyncioTask(futures.QAsyncioFuture): def _step(self, exception_or_future: typing.Union[ - Exception, futures.QAsyncioFuture, None] = None) -> None: + BaseException, futures.QAsyncioFuture, None] = None) -> None: if self.done(): return result = None @@ -72,13 +72,13 @@ class QAsyncioTask(futures.QAsyncioFuture): if exception_or_future is None: result = self._coro.send(None) elif asyncio.futures.isfuture(exception_or_future): - # If the future has an exception set by set_exception(), this will raise it. - # If the future has been cancelled, this will raise CancelledError. - # If the future's result isn't yet available, this will raise InvalidStateError. - exception_or_future.result() - exception_or_future = None - result = self._coro.send(None) - elif isinstance(exception_or_future, Exception): + 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): result = self._coro.throw(exception_or_future) except StopIteration as e: self._state = futures.QAsyncioFuture.FutureState.DONE_WITH_RESULT @@ -86,15 +86,18 @@ class QAsyncioTask(futures.QAsyncioFuture): except concurrent.futures.CancelledError as e: self._state = futures.QAsyncioFuture.FutureState.CANCELLED self._exception = e - except Exception as e: + except BaseException as e: self._state = futures.QAsyncioFuture.FutureState.DONE_WITH_EXCEPTION self._exception = e # type: ignore[assignment] else: if asyncio.futures.isfuture(result): result.add_done_callback( self._step, context=self._context) # type: ignore[arg-type] + elif result is None: + self._loop.call_soon(self._step, context=self._context) else: - self._loop.call_soon(self._step, exception_or_future, context=self._context) + exception = RuntimeError(f"Bad task result: {result}") + self._loop.call_soon(self._step, exception, context=self._context) finally: asyncio._leave_task(self._loop, self) # type: ignore[arg-type] if self._exception: |
