Skip to content

Commit 0c57f88

Browse files
committed
try import from qtpy
1 parent 047f4f5 commit 0c57f88

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/pytestqt/qtbot.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import contextlib
22
import weakref
33
import warnings
4+
from typing import TYPE_CHECKING, Callable, Optional
45

56
from pytestqt.exceptions import TimeoutError, ScreenshotError
67
from pytestqt.qt_compat import qt_api
@@ -13,6 +14,11 @@
1314
CallbackCalledTwiceError,
1415
)
1516

17+
if TYPE_CHECKING:
18+
from qtpy.QtWidgets import QWidget
19+
20+
BeforeCloseFunc = Callable[["QWidget"], None]
21+
1622

1723
def _parse_ini_boolean(value):
1824
if value in (True, False):
@@ -170,7 +176,9 @@ def _should_raise(self, raising_arg):
170176
else:
171177
return True
172178

173-
def addWidget(self, widget, *, before_close_func=None):
179+
def addWidget(
180+
self, widget: "QWidget", *, before_close_func: Optional[BeforeCloseFunc] = None
181+
):
174182
"""
175183
Adds a widget to be tracked by this bot. This is not required, but will ensure that the
176184
widget gets closed by the end of the test, so it is highly recommended.
@@ -731,7 +739,12 @@ def mouseRelease(*args, **kwargs):
731739
QtBot.CallbackCalledTwiceError = CallbackCalledTwiceError
732740

733741

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+
):
735748
"""
736749
Register a widget into the given pytest item for later closing.
737750
"""

0 commit comments

Comments
 (0)