11import contextlib
22import weakref
33import warnings
4- from typing import TYPE_CHECKING , Callable , Optional , Any
4+ from typing import TYPE_CHECKING , Callable , Optional , Any , cast
55
66from pytestqt .exceptions import TimeoutError , ScreenshotError
77from pytestqt .qt_compat import qt_api
1919 # versions possibly using 'qtpy' library.
2020 QWidget = Any
2121
22- BeforeCloseFunc = Callable [[QWidget ], None ]
22+ BeforeCloseFunc = Callable [[" QWidget" ], None ]
2323
2424
25- def _parse_ini_boolean (value ) :
25+ def _parse_ini_boolean (value : bool | str ) -> bool :
2626 if value in (True , False ):
27- return value
27+ return cast ( "bool" , value )
2828 try :
29- return {"true" : True , "false" : False }[value .lower ()]
29+ return {"true" : True , "false" : False }[cast ( "str" , value ) .lower ()]
3030 except KeyError :
3131 raise ValueError ("unknown string for bool: %r" % value )
3232
@@ -178,9 +178,7 @@ def _should_raise(self, raising_arg):
178178 else :
179179 return True
180180
181- def addWidget (
182- self , widget : "QWidget" , * , before_close_func : Optional [BeforeCloseFunc ] = None
183- ):
181+ def addWidget (self , widget , * , before_close_func : Optional [BeforeCloseFunc ] = None ):
184182 """
185183 Adds a widget to be tracked by this bot. This is not required, but will ensure that the
186184 widget gets closed by the end of the test, so it is highly recommended.
@@ -198,7 +196,7 @@ def addWidget(
198196 raise TypeError (f"Need to pass a QWidget to addWidget: { widget !r} " )
199197 _add_widget (self ._request .node , widget , before_close_func = before_close_func )
200198
201- def waitActive (self , widget , * , timeout = 5000 ):
199+ def waitActive (self , widget , * , timeout : int = 5000 ):
202200 """
203201 Context manager that waits for ``timeout`` milliseconds or until the window is active.
204202 If window is not exposed within ``timeout`` milliseconds, raise
@@ -743,7 +741,7 @@ def mouseRelease(*args, **kwargs):
743741
744742def _add_widget (
745743 item ,
746- widget : "QWidget" ,
744+ widget ,
747745 * ,
748746 before_close_func : Optional [BeforeCloseFunc ] = None ,
749747):
0 commit comments