1
1
import contextlib
2
2
import weakref
3
3
import warnings
4
- from typing import TYPE_CHECKING , Callable , Optional , Any
4
+ from typing import TYPE_CHECKING , Callable , Optional , Any , cast
5
5
6
6
from pytestqt .exceptions import TimeoutError , ScreenshotError
7
7
from pytestqt .qt_compat import qt_api
19
19
# versions possibly using 'qtpy' library.
20
20
QWidget = Any
21
21
22
- BeforeCloseFunc = Callable [[QWidget ], None ]
22
+ BeforeCloseFunc = Callable [[" QWidget" ], None ]
23
23
24
24
25
- def _parse_ini_boolean (value ) :
25
+ def _parse_ini_boolean (value : bool | str ) -> bool :
26
26
if value in (True , False ):
27
- return value
27
+ return cast ( "bool" , value )
28
28
try :
29
- return {"true" : True , "false" : False }[value .lower ()]
29
+ return {"true" : True , "false" : False }[cast ( "str" , value ) .lower ()]
30
30
except KeyError :
31
31
raise ValueError ("unknown string for bool: %r" % value )
32
32
@@ -178,9 +178,7 @@ def _should_raise(self, raising_arg):
178
178
else :
179
179
return True
180
180
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 ):
184
182
"""
185
183
Adds a widget to be tracked by this bot. This is not required, but will ensure that the
186
184
widget gets closed by the end of the test, so it is highly recommended.
@@ -198,7 +196,7 @@ def addWidget(
198
196
raise TypeError (f"Need to pass a QWidget to addWidget: { widget !r} " )
199
197
_add_widget (self ._request .node , widget , before_close_func = before_close_func )
200
198
201
- def waitActive (self , widget , * , timeout = 5000 ):
199
+ def waitActive (self , widget , * , timeout : int = 5000 ):
202
200
"""
203
201
Context manager that waits for ``timeout`` milliseconds or until the window is active.
204
202
If window is not exposed within ``timeout`` milliseconds, raise
@@ -743,7 +741,7 @@ def mouseRelease(*args, **kwargs):
743
741
744
742
def _add_widget (
745
743
item ,
746
- widget : "QWidget" ,
744
+ widget ,
747
745
* ,
748
746
before_close_func : Optional [BeforeCloseFunc ] = None ,
749
747
):
0 commit comments