diff options
| author | Adrian Herrmann <adrian.herrmann@qt.io> | 2024-06-17 23:04:43 +0200 |
|---|---|---|
| committer | Adrian Herrmann <adrian.herrmann@qt.io> | 2024-06-27 19:19:07 +0200 |
| commit | dfc0d9cd4103b9c075169be969f88aaac42a003e (patch) | |
| tree | 9d7f988afc060e63fd06e2cb5438f2d8417e4df6 /sources/pyside6 | |
| parent | 68d2b13a44fffcc72fe8aef88a194f1ed78ef1f2 (diff) | |
QtAsyncio: Remove application arg from loop policy
Remove the optional application argument from the constructor of
QAsyncioEventLoopPolicy, as it is unnecessary. If a QCoreApplication or
other type of qApp was created outside of QtAsyncio, it will always be
retrieved by QCoreApplication.instance(), and therefore passing it as an
argument makes little sense.
Task-number: PYSIDE-769
Change-Id: Iac7a913a1c9d6ebbb0984fe11f8b5cda955baab1
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6')
| -rw-r--r-- | sources/pyside6/PySide6/QtAsyncio/__init__.py | 7 | ||||
| -rw-r--r-- | sources/pyside6/PySide6/QtAsyncio/events.py | 8 | ||||
| -rw-r--r-- | sources/pyside6/doc/PySide6/QtAsyncio/index.rst | 3 |
3 files changed, 10 insertions, 8 deletions
diff --git a/sources/pyside6/PySide6/QtAsyncio/__init__.py b/sources/pyside6/PySide6/QtAsyncio/__init__.py index 08332f621..1d5854abb 100644 --- a/sources/pyside6/PySide6/QtAsyncio/__init__.py +++ b/sources/pyside6/PySide6/QtAsyncio/__init__.py @@ -23,7 +23,12 @@ def run(coro: typing.Optional[typing.Coroutine] = None, quit_qapp: bool = True, *, handle_sigint: bool = False, debug: typing.Optional[bool] = None) -> typing.Any: - """Run the QtAsyncio event loop.""" + """ + Run the QtAsyncio event loop. + + If there is no instance of a QCoreApplication, QGuiApplication or + QApplication yet, a new instance of QCoreApplication is created. + """ # Event loop policies are expected to be deprecated with Python 3.13, with # subsequent removal in Python 3.15. At that point, part of the current diff --git a/sources/pyside6/PySide6/QtAsyncio/events.py b/sources/pyside6/PySide6/QtAsyncio/events.py index 1f838226d..f104f96ea 100644 --- a/sources/pyside6/PySide6/QtAsyncio/events.py +++ b/sources/pyside6/PySide6/QtAsyncio/events.py @@ -91,16 +91,10 @@ class QAsyncioEventLoopPolicy(asyncio.AbstractEventLoopPolicy): https://discuss.python.org/t/removing-the-asyncio-policy-system-asyncio-set-event-loop-policy-in-python-3-15/37553 """ def __init__(self, - application: typing.Optional[QCoreApplication] = None, quit_qapp: bool = True, handle_sigint: bool = False) -> None: super().__init__() - if application is None: - if QCoreApplication.instance() is None: - application = QCoreApplication() - else: - application = QCoreApplication.instance() - self._application: QCoreApplication = application # type: ignore[assignment] + self._application = QCoreApplication.instance() or QCoreApplication() # Configure whether the QCoreApplication at the core of QtAsyncio # should be shut down when asyncio finishes. A special case where one diff --git a/sources/pyside6/doc/PySide6/QtAsyncio/index.rst b/sources/pyside6/doc/PySide6/QtAsyncio/index.rst index 326f6efcc..0ad0f6f97 100644 --- a/sources/pyside6/doc/PySide6/QtAsyncio/index.rst +++ b/sources/pyside6/doc/PySide6/QtAsyncio/index.rst @@ -118,6 +118,9 @@ or to run the coroutine and then stop the event loop upon its completion. This latter case behaves identically to ``asyncio.run(my_coroutine())``. +If there is no instance of a QCoreApplication, QGuiApplication or +QApplication yet, a new instance of QCoreApplication is created. + An additional optional argument ``quit_qapp`` can be passed to ``run()`` to configure whether the QCoreApplication at the core of QtAsyncio should be shut down when asyncio finishes. A special case where one |
