|
1 | 1 | import contextlib
|
2 | 2 | import weakref
|
3 | 3 | import warnings
|
| 4 | +from typing import TYPE_CHECKING, Callable, Optional |
4 | 5 |
|
5 | 6 | from pytestqt.exceptions import TimeoutError, ScreenshotError
|
6 | 7 | from pytestqt.qt_compat import qt_api
|
|
13 | 14 | CallbackCalledTwiceError,
|
14 | 15 | )
|
15 | 16 |
|
| 17 | +if TYPE_CHECKING: |
| 18 | + from qtpy.QtWidgets import QWidget |
| 19 | + |
| 20 | +BeforeCloseFunc = Callable[["QWidget"], None] |
| 21 | + |
16 | 22 |
|
17 | 23 | def _parse_ini_boolean(value):
|
18 | 24 | if value in (True, False):
|
@@ -170,7 +176,9 @@ def _should_raise(self, raising_arg):
|
170 | 176 | else:
|
171 | 177 | return True
|
172 | 178 |
|
173 |
| - def addWidget(self, widget, *, before_close_func=None): |
| 179 | + def addWidget( |
| 180 | + self, widget: "QWidget", *, before_close_func: Optional[BeforeCloseFunc] = None |
| 181 | + ): |
174 | 182 | """
|
175 | 183 | Adds a widget to be tracked by this bot. This is not required, but will ensure that the
|
176 | 184 | widget gets closed by the end of the test, so it is highly recommended.
|
@@ -731,7 +739,12 @@ def mouseRelease(*args, **kwargs):
|
731 | 739 | QtBot.CallbackCalledTwiceError = CallbackCalledTwiceError
|
732 | 740 |
|
733 | 741 |
|
734 |
| -def _add_widget(item, widget, *, before_close_func=None): |
| 742 | +def _add_widget( |
| 743 | + item: object, |
| 744 | + widget: "QWidget", |
| 745 | + *, |
| 746 | + before_close_func: Optional[BeforeCloseFunc] = None, |
| 747 | +): |
735 | 748 | """
|
736 | 749 | Register a widget into the given pytest item for later closing.
|
737 | 750 | """
|
|
0 commit comments