Skip to content

Commit 6d15373

Browse files
Fix incorrect use of 'NoReturn' type annotation. (#9540)
When a function or method explicitly or implicitly returns None, its return type annotation should be 'None'. 'NoReturn' should only be used when a function or method never returns e.g., it always raises an Exception. Co-authored-by: David Burns <david.burns@theautomatedtester.co.uk>
1 parent 8d1a5e3 commit 6d15373

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

py/selenium/webdriver/remote/webdriver.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222
import pkgutil
2323
import sys
24-
from typing import (Dict, List,
25-
NoReturn, Union)
24+
from typing import Dict, List, Union
2625

2726
import warnings
2827

@@ -318,7 +317,7 @@ def stop_client(self):
318317
"""
319318
pass
320319

321-
def start_session(self, capabilities: dict, browser_profile=None) -> NoReturn:
320+
def start_session(self, capabilities: dict, browser_profile=None) -> None:
322321
"""
323322
Creates a new session with the desired capabilities.
324323
@@ -405,7 +404,7 @@ def execute(self, driver_command: str, params: dict = None) -> dict:
405404
# a success
406405
return {'success': 0, 'value': None, 'sessionId': self.session_id}
407406

408-
def get(self, url: str) -> NoReturn:
407+
def get(self, url: str) -> None:
409408
"""
410409
Loads a web page in the current browser session.
411410
"""
@@ -753,7 +752,7 @@ def pin_script(self, script, script_key=None) -> ScriptKey:
753752
self.pinned_scripts[_script_key.id] = script
754753
return _script_key
755754

756-
def unpin(self, script_key) -> NoReturn:
755+
def unpin(self, script_key) -> None:
757756
"""
758757
759758
"""
@@ -837,7 +836,7 @@ def page_source(self) -> str:
837836
"""
838837
return self.execute(Command.GET_PAGE_SOURCE)['value']
839838

840-
def close(self) -> NoReturn:
839+
def close(self) -> None:
841840
"""
842841
Closes the current window.
843842
@@ -848,7 +847,7 @@ def close(self) -> NoReturn:
848847
"""
849848
self.execute(Command.CLOSE)
850849

851-
def quit(self) -> NoReturn:
850+
def quit(self) -> None:
852851
"""
853852
Quits the driver and closes every associated window.
854853
@@ -887,21 +886,21 @@ def window_handles(self) -> List[str]:
887886
"""
888887
return self.execute(Command.W3C_GET_WINDOW_HANDLES)['value']
889888

890-
def maximize_window(self) -> NoReturn:
889+
def maximize_window(self) -> None:
891890
"""
892891
Maximizes the current window that webdriver is using
893892
"""
894893
params = None
895894
command = Command.W3C_MAXIMIZE_WINDOW
896895
self.execute(command, params)
897896

898-
def fullscreen_window(self) -> NoReturn:
897+
def fullscreen_window(self) -> None:
899898
"""
900899
Invokes the window manager-specific 'full screen' operation
901900
"""
902901
self.execute(Command.FULLSCREEN_WINDOW)
903902

904-
def minimize_window(self) -> NoReturn:
903+
def minimize_window(self) -> None:
905904
"""
906905
Invokes the window manager-specific 'minimize' operation
907906
"""
@@ -939,7 +938,7 @@ def switch_to(self) -> SwitchTo:
939938
return self._switch_to
940939

941940
# Navigation
942-
def back(self) -> NoReturn:
941+
def back(self) -> None:
943942
"""
944943
Goes one step backward in the browser history.
945944
@@ -950,7 +949,7 @@ def back(self) -> NoReturn:
950949
"""
951950
self.execute(Command.GO_BACK)
952951

953-
def forward(self) -> NoReturn:
952+
def forward(self) -> None:
954953
"""
955954
Goes one step forward in the browser history.
956955
@@ -961,7 +960,7 @@ def forward(self) -> NoReturn:
961960
"""
962961
self.execute(Command.GO_FORWARD)
963962

964-
def refresh(self) -> NoReturn:
963+
def refresh(self) -> None:
965964
"""
966965
Refreshes the current page.
967966
@@ -998,7 +997,7 @@ def get_cookie(self, name) -> dict:
998997
except NoSuchCookieException:
999998
return None
1000999

1001-
def delete_cookie(self, name) -> NoReturn:
1000+
def delete_cookie(self, name) -> None:
10021001
"""
10031002
Deletes a single cookie with the given name.
10041003
@@ -1009,7 +1008,7 @@ def delete_cookie(self, name) -> NoReturn:
10091008
"""
10101009
self.execute(Command.DELETE_COOKIE, {'name': name})
10111010

1012-
def delete_all_cookies(self) -> NoReturn:
1011+
def delete_all_cookies(self) -> None:
10131012
"""
10141013
Delete all cookies in the scope of the session.
10151014
@@ -1020,7 +1019,7 @@ def delete_all_cookies(self) -> NoReturn:
10201019
"""
10211020
self.execute(Command.DELETE_ALL_COOKIES)
10221021

1023-
def add_cookie(self, cookie_dict) -> NoReturn:
1022+
def add_cookie(self, cookie_dict) -> None:
10241023
"""
10251024
Adds a cookie to your current session.
10261025
@@ -1042,7 +1041,7 @@ def add_cookie(self, cookie_dict) -> NoReturn:
10421041
self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})
10431042

10441043
# Timeouts
1045-
def implicitly_wait(self, time_to_wait) -> NoReturn:
1044+
def implicitly_wait(self, time_to_wait) -> None:
10461045
"""
10471046
Sets a sticky timeout to implicitly wait for an element to be found,
10481047
or a command to complete. This method only needs to be called one
@@ -1060,7 +1059,7 @@ def implicitly_wait(self, time_to_wait) -> NoReturn:
10601059
self.execute(Command.SET_TIMEOUTS, {
10611060
'implicit': int(float(time_to_wait) * 1000)})
10621061

1063-
def set_script_timeout(self, time_to_wait) -> NoReturn:
1062+
def set_script_timeout(self, time_to_wait) -> None:
10641063
"""
10651064
Set the amount of time that the script should wait during an
10661065
execute_async_script call before throwing an error.
@@ -1076,7 +1075,7 @@ def set_script_timeout(self, time_to_wait) -> NoReturn:
10761075
self.execute(Command.SET_TIMEOUTS, {
10771076
'script': int(float(time_to_wait) * 1000)})
10781077

1079-
def set_page_load_timeout(self, time_to_wait) -> NoReturn:
1078+
def set_page_load_timeout(self, time_to_wait) -> None:
10801079
"""
10811080
Set the amount of time to wait for a page load to complete
10821081
before throwing an error.
@@ -1114,7 +1113,7 @@ def timeouts(self) -> Timeouts:
11141113
return Timeouts(**timeouts)
11151114

11161115
@timeouts.setter
1117-
def timeouts(self, timeouts) -> NoReturn:
1116+
def timeouts(self, timeouts) -> None:
11181117
"""
11191118
Set all timeouts for the session. This will override any previously
11201119
set timeouts.

0 commit comments

Comments
 (0)