Skip to content

Commit d05680d

Browse files
[py] Fix mypy errors in by file and exceptions file (#16300)
Co-authored-by: Corey Goldberg <1113081+cgoldberg@users.noreply.github.com>
1 parent f7c6590 commit d05680d

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

py/selenium/common/exceptions.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"""Exceptions that may happen in all the webdriver code."""
1818

1919
from collections.abc import Sequence
20-
from typing import Optional
20+
from typing import Any, Optional
2121

2222
SUPPORT_MSG = "For documentation on this error, please visit:"
2323
ERROR_URL = "https://www.selenium.dev/documentation/webdriver/troubleshooting/errors"
@@ -27,7 +27,7 @@ class WebDriverException(Exception):
2727
"""Base webdriver exception."""
2828

2929
def __init__(
30-
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
30+
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
3131
) -> None:
3232
super().__init__()
3333
self.msg = msg
@@ -73,7 +73,7 @@ class NoSuchElementException(WebDriverException):
7373
"""
7474

7575
def __init__(
76-
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
76+
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
7777
) -> None:
7878
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#nosuchelementexception"
7979

@@ -112,7 +112,7 @@ class StaleElementReferenceException(WebDriverException):
112112
"""
113113

114114
def __init__(
115-
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
115+
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
116116
) -> None:
117117
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#staleelementreferenceexception"
118118

@@ -137,7 +137,7 @@ class UnexpectedAlertPresentException(WebDriverException):
137137

138138
def __init__(
139139
self,
140-
msg: Optional[str] = None,
140+
msg: Optional[Any] = None,
141141
screen: Optional[str] = None,
142142
stacktrace: Optional[Sequence[str]] = None,
143143
alert_text: Optional[str] = None,
@@ -166,7 +166,7 @@ class ElementNotVisibleException(InvalidElementStateException):
166166
"""
167167

168168
def __init__(
169-
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
169+
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
170170
) -> None:
171171
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#elementnotvisibleexception"
172172

@@ -178,7 +178,7 @@ class ElementNotInteractableException(InvalidElementStateException):
178178
element will hit another element due to paint order."""
179179

180180
def __init__(
181-
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
181+
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
182182
) -> None:
183183
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#elementnotinteractableexception"
184184

@@ -225,7 +225,7 @@ class InvalidSelectorException(WebDriverException):
225225
"""
226226

227227
def __init__(
228-
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
228+
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
229229
) -> None:
230230
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#invalidselectorexception"
231231

@@ -267,7 +267,7 @@ class ElementClickInterceptedException(WebDriverException):
267267
clicked."""
268268

269269
def __init__(
270-
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
270+
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
271271
) -> None:
272272
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#elementclickinterceptedexception"
273273

@@ -288,7 +288,7 @@ class InvalidSessionIdException(WebDriverException):
288288
meaning the session either does not exist or that it's not active."""
289289

290290
def __init__(
291-
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
291+
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
292292
) -> None:
293293
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#invalidsessionidexception"
294294

@@ -299,7 +299,7 @@ class SessionNotCreatedException(WebDriverException):
299299
"""A new session could not be created."""
300300

301301
def __init__(
302-
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
302+
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
303303
) -> None:
304304
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#sessionnotcreatedexception"
305305

@@ -315,7 +315,7 @@ class NoSuchDriverException(WebDriverException):
315315
"""Raised when driver is not specified and cannot be located."""
316316

317317
def __init__(
318-
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
318+
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
319319
) -> None:
320320
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}/driver_location"
321321

py/selenium/webdriver/common/by.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
from typing import Literal, Optional
2020

21+
ByType = Literal["id", "xpath", "link text", "partial link text", "name", "tag name", "class name", "css selector"]
22+
2123

2224
class By:
2325
"""Set of supported locator strategies.
@@ -73,14 +75,14 @@ class By:
7375
>>> element = driver.find_element(By.CSS_SELECTOR, "div.myElement")
7476
"""
7577

76-
ID = "id"
77-
XPATH = "xpath"
78-
LINK_TEXT = "link text"
79-
PARTIAL_LINK_TEXT = "partial link text"
80-
NAME = "name"
81-
TAG_NAME = "tag name"
82-
CLASS_NAME = "class name"
83-
CSS_SELECTOR = "css selector"
78+
ID: ByType = "id"
79+
XPATH: ByType = "xpath"
80+
LINK_TEXT: ByType = "link text"
81+
PARTIAL_LINK_TEXT: ByType = "partial link text"
82+
NAME: ByType = "name"
83+
TAG_NAME: ByType = "tag name"
84+
CLASS_NAME: ByType = "class name"
85+
CSS_SELECTOR: ByType = "css selector"
8486

8587
_custom_finders: dict[str, str] = {}
8688

@@ -95,6 +97,3 @@ def get_finder(cls, name: str) -> Optional[str]:
9597
@classmethod
9698
def clear_custom_finders(cls) -> None:
9799
cls._custom_finders.clear()
98-
99-
100-
ByType = Literal["id", "xpath", "link text", "partial link text", "name", "tag name", "class name", "css selector"]

0 commit comments

Comments
 (0)