Skip to content

Commit 878feb7

Browse files
committed
[py]: Sweeping typing improvements for all property setters
1 parent 5604523 commit 878feb7

11 files changed

Lines changed: 64 additions & 60 deletions

File tree

py/selenium/webdriver/common/options.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
17+
import typing
1818
from abc import ABCMeta, abstractmethod
19-
from selenium.webdriver.common.proxy import Proxy
19+
2020
from selenium.common.exceptions import InvalidArgumentException
21+
from selenium.webdriver.common.proxy import Proxy
2122

2223

2324
class BaseOptions(metaclass=ABCMeta):
@@ -35,7 +36,7 @@ def __init__(self) -> None:
3536
def capabilities(self):
3637
return self._caps
3738

38-
def set_capability(self, name, value):
39+
def set_capability(self, name, value) -> None:
3940
""" Sets a capability """
4041
self._caps[name] = value
4142

@@ -128,12 +129,13 @@ def timeouts(self, timeouts: dict) -> None:
128129
129130
:param timeouts: values in milliseconds for implicit wait, page load and script timeout
130131
"""
131-
if all(x in timeouts.keys() for x in ["implicit", "pageLoad", "script"]):
132+
if all(x in timeouts.keys() for x in ("implicit", "pageLoad", "script")):
132133
self.set_capability("timeouts", timeouts)
133134
else:
134135
raise ValueError("Timeout keys can only be one of the following: implicit, pageLoad, script")
135136

136-
def enable_mobile(self, android_package: str = None, android_activity: str = None, device_serial: str = None):
137+
def enable_mobile(self, android_package: typing.Optional[str] = None, android_activity: typing.Optional[str] = None,
138+
device_serial: typing.Optional[str] = None) -> None:
137139
"""
138140
Enables mobile browser use for browsers that support it
139141
@@ -175,7 +177,7 @@ def strict_file_interactability(self) -> bool:
175177
return self._caps.get('strictFileInteractability')
176178

177179
@strict_file_interactability.setter
178-
def strict_file_interactability(self, value: bool):
180+
def strict_file_interactability(self, value: bool) -> None:
179181
"""
180182
Whether interactability checks will be applied to file type input elements. The default is false.
181183
@@ -191,7 +193,7 @@ def set_window_rect(self) -> bool:
191193
return self._caps.get('setWindowRect')
192194

193195
@set_window_rect.setter
194-
def set_window_rect(self, value: bool):
196+
def set_window_rect(self, value: bool) -> None:
195197
"""
196198
Whether the remote end supports all of the resizing and positioning commands. The default is false.
197199
https://w3c.github.io/webdriver/#dfn-strict-file-interactability
@@ -208,7 +210,7 @@ def proxy(self) -> Proxy:
208210
return self._proxy
209211

210212
@proxy.setter
211-
def proxy(self, value: Proxy):
213+
def proxy(self, value: Proxy) -> None:
212214
if not isinstance(value, Proxy):
213215
raise InvalidArgumentException("Only Proxy objects can be passed in.")
214216
self._proxy = value

py/selenium/webdriver/common/proxy.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def proxy_type(self):
115115
return self.proxyType
116116

117117
@proxy_type.setter
118-
def proxy_type(self, value):
118+
def proxy_type(self, value) -> None:
119119
"""
120120
Sets proxy type.
121121
@@ -133,7 +133,7 @@ def auto_detect(self):
133133
return self.autodetect
134134

135135
@auto_detect.setter
136-
def auto_detect(self, value):
136+
def auto_detect(self, value) -> None:
137137
"""
138138
Sets autodetect setting.
139139
@@ -156,7 +156,7 @@ def ftp_proxy(self):
156156
return self.ftpProxy
157157

158158
@ftp_proxy.setter
159-
def ftp_proxy(self, value):
159+
def ftp_proxy(self, value) -> None:
160160
"""
161161
Sets ftp proxy setting.
162162
@@ -175,7 +175,7 @@ def http_proxy(self):
175175
return self.httpProxy
176176

177177
@http_proxy.setter
178-
def http_proxy(self, value):
178+
def http_proxy(self, value) -> None:
179179
"""
180180
Sets http proxy setting.
181181
@@ -194,7 +194,7 @@ def no_proxy(self):
194194
return self.noProxy
195195

196196
@no_proxy.setter
197-
def no_proxy(self, value):
197+
def no_proxy(self, value) -> None:
198198
"""
199199
Sets noproxy setting.
200200
@@ -213,7 +213,7 @@ def proxy_autoconfig_url(self):
213213
return self.proxyAutoconfigUrl
214214

215215
@proxy_autoconfig_url.setter
216-
def proxy_autoconfig_url(self, value):
216+
def proxy_autoconfig_url(self, value) -> None:
217217
"""
218218
Sets proxy autoconfig url setting.
219219
@@ -232,7 +232,7 @@ def ssl_proxy(self):
232232
return self.sslProxy
233233

234234
@ssl_proxy.setter
235-
def ssl_proxy(self, value):
235+
def ssl_proxy(self, value) -> None:
236236
"""
237237
Sets https proxy setting.
238238
@@ -251,7 +251,7 @@ def socks_proxy(self):
251251
return self.socksProxy
252252

253253
@socks_proxy.setter
254-
def socks_proxy(self, value):
254+
def socks_proxy(self, value) -> None:
255255
"""
256256
Sets socks proxy setting.
257257
@@ -270,7 +270,7 @@ def socks_username(self):
270270
return self.socksUsername
271271

272272
@socks_username.setter
273-
def socks_username(self, value):
273+
def socks_username(self, value) -> None:
274274
"""
275275
Sets socks proxy username setting.
276276
@@ -289,7 +289,7 @@ def socks_password(self):
289289
return self.socksPassword
290290

291291
@socks_password.setter
292-
def socks_password(self, value):
292+
def socks_password(self, value) -> None:
293293
"""
294294
Sets socks proxy password setting.
295295
@@ -308,7 +308,7 @@ def socks_version(self):
308308
return self.socksVersion
309309

310310
@socks_version.setter
311-
def socks_version(self, value):
311+
def socks_version(self, value) -> None:
312312
"""
313313
Sets socks proxy version setting.
314314

py/selenium/webdriver/edge/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def use_webview(self) -> bool:
3131
return self._use_webview
3232

3333
@use_webview.setter
34-
def use_webview(self, value: bool):
34+
def use_webview(self, value: bool) -> None:
3535
self._use_webview = bool(value)
3636

3737
def to_capabilities(self) -> dict:

py/selenium/webdriver/firefox/firefox_profile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def port(self):
117117
return self._port
118118

119119
@port.setter
120-
def port(self, port):
120+
def port(self, port) -> None:
121121
"""
122122
Sets the port that WebDriver will be running on
123123
"""
@@ -137,7 +137,7 @@ def accept_untrusted_certs(self):
137137
return self.default_preferences["webdriver_accept_untrusted_certs"]
138138

139139
@accept_untrusted_certs.setter
140-
def accept_untrusted_certs(self, value):
140+
def accept_untrusted_certs(self, value) -> None:
141141
if value not in [True, False]:
142142
raise WebDriverException("Please pass in a Boolean to this call")
143143
self.set_preference("webdriver_accept_untrusted_certs", value)
@@ -147,7 +147,7 @@ def assume_untrusted_cert_issuer(self):
147147
return self.default_preferences["webdriver_assume_untrusted_issuer"]
148148

149149
@assume_untrusted_cert_issuer.setter
150-
def assume_untrusted_cert_issuer(self, value):
150+
def assume_untrusted_cert_issuer(self, value) -> None:
151151
if value not in [True, False]:
152152
raise WebDriverException("Please pass in a Boolean to this call")
153153

py/selenium/webdriver/firefox/options.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def binary(self) -> FirefoxBinary:
4949
return self._binary
5050

5151
@binary.setter
52-
def binary(self, new_binary: Union[str, FirefoxBinary]):
52+
def binary(self, new_binary: Union[str, FirefoxBinary]) -> None:
5353
"""Sets location of the browser binary, either by string or
5454
``FirefoxBinary`` instance.
5555
@@ -66,7 +66,7 @@ def binary_location(self) -> str:
6666
return self.binary._start_cmd
6767

6868
@binary_location.setter # noqa
69-
def binary_location(self, value: str):
69+
def binary_location(self, value: str) -> None:
7070
""" Sets the location of the browser binary by string """
7171
self.binary = value
7272

@@ -93,7 +93,7 @@ def profile(self) -> FirefoxProfile:
9393
return self._profile
9494

9595
@profile.setter
96-
def profile(self, new_profile: Union[str, FirefoxProfile]):
96+
def profile(self, new_profile: Union[str, FirefoxProfile]) -> None:
9797
"""Sets location of the browser profile to use, either by string
9898
or ``FirefoxProfile``.
9999
@@ -115,7 +115,7 @@ def headless(self) -> bool:
115115
return '-headless' in self._arguments
116116

117117
@headless.setter
118-
def headless(self, value: bool):
118+
def headless(self, value: bool) -> None:
119119
"""
120120
Sets the headless argument
121121

py/selenium/webdriver/ie/options.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def browser_attach_timeout(self) -> int:
6666
return self._options.get(self.BROWSER_ATTACH_TIMEOUT)
6767

6868
@browser_attach_timeout.setter
69-
def browser_attach_timeout(self, value: int):
69+
def browser_attach_timeout(self, value: int) -> None:
7070
"""
7171
Sets the options Browser Attach Timeout
7272
@@ -84,7 +84,7 @@ def element_scroll_behavior(self) -> ElementScrollBehavior:
8484
return self._options.get(self.ELEMENT_SCROLL_BEHAVIOR)
8585

8686
@element_scroll_behavior.setter
87-
def element_scroll_behavior(self, value: ElementScrollBehavior):
87+
def element_scroll_behavior(self, value: ElementScrollBehavior) -> None:
8888
"""
8989
Sets the options Element Scroll Behavior
9090
@@ -102,7 +102,7 @@ def ensure_clean_session(self) -> bool:
102102
return self._options.get(self.ENSURE_CLEAN_SESSION)
103103

104104
@ensure_clean_session.setter
105-
def ensure_clean_session(self, value: bool):
105+
def ensure_clean_session(self, value: bool) -> None:
106106
"""
107107
Sets the options Ensure Clean Session value
108108
@@ -118,7 +118,7 @@ def file_upload_dialog_timeout(self) -> int:
118118
return self._options.get(self.FILE_UPLOAD_DIALOG_TIMEOUT)
119119

120120
@file_upload_dialog_timeout.setter
121-
def file_upload_dialog_timeout(self, value: int):
121+
def file_upload_dialog_timeout(self, value: int) -> None:
122122
"""
123123
Sets the options File Upload Dialog Timeout value
124124
@@ -136,7 +136,7 @@ def force_create_process_api(self) -> bool:
136136
return self._options.get(self.FORCE_CREATE_PROCESS_API)
137137

138138
@force_create_process_api.setter
139-
def force_create_process_api(self, value: bool):
139+
def force_create_process_api(self, value: bool) -> None:
140140
"""
141141
Sets the options Force Create Process Api value
142142
@@ -152,7 +152,7 @@ def force_shell_windows_api(self) -> bool:
152152
return self._options.get(self.FORCE_SHELL_WINDOWS_API)
153153

154154
@force_shell_windows_api.setter
155-
def force_shell_windows_api(self, value: bool):
155+
def force_shell_windows_api(self, value: bool) -> None:
156156
"""
157157
Sets the options Force Shell Windows Api value
158158
@@ -168,7 +168,7 @@ def full_page_screenshot(self) -> bool:
168168
return self._options.get(self.FULL_PAGE_SCREENSHOT)
169169

170170
@full_page_screenshot.setter
171-
def full_page_screenshot(self, value: bool):
171+
def full_page_screenshot(self, value: bool) -> None:
172172
"""
173173
Sets the options Full Page Screenshot value
174174
@@ -184,7 +184,7 @@ def ignore_protected_mode_settings(self) -> bool:
184184
return self._options.get(self.IGNORE_PROTECTED_MODE_SETTINGS)
185185

186186
@ignore_protected_mode_settings.setter
187-
def ignore_protected_mode_settings(self, value: bool):
187+
def ignore_protected_mode_settings(self, value: bool) -> None:
188188
"""
189189
Sets the options Ignore Protected Mode Settings value
190190
@@ -200,7 +200,7 @@ def ignore_zoom_level(self) -> bool:
200200
return self._options.get(self.IGNORE_ZOOM_LEVEL)
201201

202202
@ignore_zoom_level.setter
203-
def ignore_zoom_level(self, value: bool):
203+
def ignore_zoom_level(self, value: bool) -> None:
204204
"""
205205
Sets the options Ignore Zoom Level value
206206
@@ -216,7 +216,7 @@ def initial_browser_url(self) -> str:
216216
return self._options.get(self.INITIAL_BROWSER_URL)
217217

218218
@initial_browser_url.setter
219-
def initial_browser_url(self, value: str):
219+
def initial_browser_url(self, value: str) -> None:
220220
"""
221221
Sets the options Initial Browser Url value
222222
@@ -232,7 +232,7 @@ def native_events(self) -> bool:
232232
return self._options.get(self.NATIVE_EVENTS)
233233

234234
@native_events.setter
235-
def native_events(self, value: bool):
235+
def native_events(self, value: bool) -> None:
236236
"""
237237
Sets the options Native Events value
238238
@@ -248,7 +248,7 @@ def persistent_hover(self) -> bool:
248248
return self._options.get(self.PERSISTENT_HOVER)
249249

250250
@persistent_hover.setter
251-
def persistent_hover(self, value: bool):
251+
def persistent_hover(self, value: bool) -> None:
252252
"""
253253
Sets the options Persistent Hover value
254254
@@ -264,7 +264,7 @@ def require_window_focus(self: bool):
264264
return self._options.get(self.REQUIRE_WINDOW_FOCUS)
265265

266266
@require_window_focus.setter
267-
def require_window_focus(self, value: bool):
267+
def require_window_focus(self, value: bool) -> None:
268268
"""
269269
Sets the options Require Window Focus value
270270
@@ -280,7 +280,7 @@ def use_per_process_proxy(self) -> bool:
280280
return self._options.get(self.USE_PER_PROCESS_PROXY)
281281

282282
@use_per_process_proxy.setter
283-
def use_per_process_proxy(self, value: bool):
283+
def use_per_process_proxy(self, value: bool) -> None:
284284
"""
285285
Sets the options User Per Process Proxy value
286286
@@ -296,7 +296,7 @@ def use_legacy_file_upload_dialog_handling(self) -> bool:
296296
return self._options.get(self.USE_LEGACY_FILE_UPLOAD_DIALOG_HANDLING)
297297

298298
@use_legacy_file_upload_dialog_handling.setter
299-
def use_legacy_file_upload_dialog_handling(self, value: bool):
299+
def use_legacy_file_upload_dialog_handling(self, value: bool) -> None:
300300
"""
301301
Sets the options Use Legacy File Upload Dialog Handling value
302302
@@ -312,7 +312,7 @@ def attach_to_edge_chrome(self) -> bool:
312312
return self._options.get(self.ATTACH_TO_EDGE_CHROME)
313313

314314
@attach_to_edge_chrome.setter
315-
def attach_to_edge_chrome(self, value: bool):
315+
def attach_to_edge_chrome(self, value: bool) -> None:
316316
"""
317317
Sets the options Attach to Edge Chrome value
318318
@@ -328,7 +328,7 @@ def edge_executable_path(self) -> str:
328328
return self._options.get(self.EDGE_EXECUTABLE_PATH)
329329

330330
@edge_executable_path.setter
331-
def edge_executable_path(self, value: str):
331+
def edge_executable_path(self, value: str) -> None:
332332
"""
333333
Sets the options Initial Browser Url value
334334

py/selenium/webdriver/remote/mobile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def contexts(self):
7979
return self._driver.execute(Command.CONTEXT_HANDLES)
8080

8181
@context.setter
82-
def context(self, new_context):
82+
def context(self, new_context) -> None:
8383
"""
8484
sets the current context
8585
"""

0 commit comments

Comments
 (0)