Skip to content

Commit c0a5c3e

Browse files
[py] PEP 484 type hints for selenium.webdriver.common.timeouts (#9524)
Signed-off-by: oleg.hoefling <[email protected]> Co-authored-by: David Burns <[email protected]>
1 parent 6d15373 commit c0a5c3e

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

py/selenium/webdriver/common/timeouts.py

+30-10
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,29 @@
1616
# under the License.
1717

1818

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+
1939
class Timeouts(object):
2040

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:
2242
"""
2343
Create a new Timeout object.
2444
@@ -35,55 +55,55 @@ def __init__(self, implicit_wait=0, page_load=0, script=0):
3555
self._script = self._convert(script)
3656

3757
@property
38-
def implicit_wait(self):
58+
def implicit_wait(self) -> float:
3959
"""
4060
Return the value for the implicit wait. This does not return the value on the remote end
4161
"""
4262
return self._implicit_wait / 1000
4363

4464
@implicit_wait.setter
45-
def implicit_wait(self, _implicit_wait):
65+
def implicit_wait(self, _implicit_wait: float) -> None:
4666
"""
4767
Sets the value for the implicit wait. This does not set the value on the remote end
4868
"""
4969
self._implicit_wait = self._convert(_implicit_wait)
5070

5171
@property
52-
def page_load(self):
72+
def page_load(self) -> float:
5373
"""
5474
Return the value for the page load wait. This does not return the value on the remote end
5575
"""
5676
return self._page_load / 1000
5777

5878
@page_load.setter
59-
def page_load(self, _page_load):
79+
def page_load(self, _page_load: float) -> None:
6080
"""
6181
Sets the value for the page load wait. This does not set the value on the remote end
6282
"""
6383
self._page_load = self._convert(_page_load)
6484

6585
@property
66-
def script(self):
86+
def script(self) -> float:
6787
"""
6888
Return the value for the script wait. This does not return the value on the remote end
6989
"""
7090
return self._script / 1000
7191

7292
@script.setter
73-
def script(self, _script):
93+
def script(self, _script: float) -> None:
7494
"""
7595
Sets the value for the script wait. This does not set the value on the remote end
7696
"""
7797
self._script = self._convert(_script)
7898

79-
def _convert(self, timeout):
99+
def _convert(self, timeout: float) -> int:
80100
if isinstance(timeout, (int, float)):
81101
return int(float(timeout) * 1000)
82102
else:
83103
raise TypeError("Timeouts can only be an int or a float")
84104

85-
def _to_json(self):
86-
timeouts = {}
105+
def _to_json(self) -> JSONTimeouts:
106+
timeouts: JSONTimeouts = {}
87107
if self._implicit_wait:
88108
timeouts["implicit"] = self._implicit_wait
89109
if self._page_load:

0 commit comments

Comments
 (0)