16
16
# under the License.
17
17
18
18
19
+ from typing import TYPE_CHECKING
20
+
21
+
22
+ if TYPE_CHECKING :
23
+ import sys
24
+ if sys .version_info >= (3 , 8 ):
25
+ from typing import TypedDict
26
+ else :
27
+ from typing_extensions import TypedDict
28
+
29
+ class JSONTimeouts (TypedDict , total = False ):
30
+ implicit : int
31
+ pageLoad : int
32
+ script : int
33
+
34
+ else :
35
+ from typing import Dict
36
+ JSONTimeouts = Dict [str , int ]
37
+
38
+
19
39
class Timeouts (object ):
20
40
21
- def __init__ (self , implicit_wait = 0 , page_load = 0 , script = 0 ) :
41
+ def __init__ (self , implicit_wait : float = 0 , page_load : float = 0 , script : float = 0 ) -> None :
22
42
"""
23
43
Create a new Timeout object.
24
44
@@ -35,55 +55,55 @@ def __init__(self, implicit_wait=0, page_load=0, script=0):
35
55
self ._script = self ._convert (script )
36
56
37
57
@property
38
- def implicit_wait (self ):
58
+ def implicit_wait (self ) -> float :
39
59
"""
40
60
Return the value for the implicit wait. This does not return the value on the remote end
41
61
"""
42
62
return self ._implicit_wait / 1000
43
63
44
64
@implicit_wait .setter
45
- def implicit_wait (self , _implicit_wait ) :
65
+ def implicit_wait (self , _implicit_wait : float ) -> None :
46
66
"""
47
67
Sets the value for the implicit wait. This does not set the value on the remote end
48
68
"""
49
69
self ._implicit_wait = self ._convert (_implicit_wait )
50
70
51
71
@property
52
- def page_load (self ):
72
+ def page_load (self ) -> float :
53
73
"""
54
74
Return the value for the page load wait. This does not return the value on the remote end
55
75
"""
56
76
return self ._page_load / 1000
57
77
58
78
@page_load .setter
59
- def page_load (self , _page_load ) :
79
+ def page_load (self , _page_load : float ) -> None :
60
80
"""
61
81
Sets the value for the page load wait. This does not set the value on the remote end
62
82
"""
63
83
self ._page_load = self ._convert (_page_load )
64
84
65
85
@property
66
- def script (self ):
86
+ def script (self ) -> float :
67
87
"""
68
88
Return the value for the script wait. This does not return the value on the remote end
69
89
"""
70
90
return self ._script / 1000
71
91
72
92
@script .setter
73
- def script (self , _script ) :
93
+ def script (self , _script : float ) -> None :
74
94
"""
75
95
Sets the value for the script wait. This does not set the value on the remote end
76
96
"""
77
97
self ._script = self ._convert (_script )
78
98
79
- def _convert (self , timeout ) :
99
+ def _convert (self , timeout : float ) -> int :
80
100
if isinstance (timeout , (int , float )):
81
101
return int (float (timeout ) * 1000 )
82
102
else :
83
103
raise TypeError ("Timeouts can only be an int or a float" )
84
104
85
- def _to_json (self ):
86
- timeouts = {}
105
+ def _to_json (self ) -> JSONTimeouts :
106
+ timeouts : JSONTimeouts = {}
87
107
if self ._implicit_wait :
88
108
timeouts ["implicit" ] = self ._implicit_wait
89
109
if self ._page_load :
0 commit comments