Skip to content

Commit a0921f2

Browse files
committed
Better documentation of type hacks in has_driver.
1 parent 5148a2c commit a0921f2

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

lib/galaxy/selenium/has_driver.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _webelement_to_protocol(element: WebElement) -> WebElementProtocol:
7777
Since WebElement actually implements all required protocol methods correctly
7878
at runtime, this cast is safe.
7979
"""
80-
return element # type: ignore[return-value]
80+
return cast(WebElementProtocol, element)
8181

8282

8383
def _webelements_to_protocol(elements: list[WebElement]) -> list[WebElementProtocol]:
@@ -86,7 +86,12 @@ def _webelements_to_protocol(elements: list[WebElement]) -> list[WebElementProto
8686
8787
See _webelement_to_protocol for why this type conversion is necessary.
8888
"""
89-
return elements # type: ignore[return-value]
89+
return [cast(WebElementProtocol, element) for element in elements]
90+
91+
92+
def _protocol_to_webelement(element: WebElementProtocol) -> WebElement:
93+
"""See notes above for why these cannot be directly typed."""
94+
return cast(WebElement, element)
9095

9196

9297
def _cookies_to_typed(cookies: list[dict]) -> list[Cookie]:
@@ -572,9 +577,7 @@ def select_by_value(self, selector_template: HasElementLocator, value: str) -> N
572577
selector_template: Either a Target or a (locator_type, value) tuple for the select element
573578
value: The value attribute of the option to select
574579
"""
575-
# Cast to WebElement - we know this is actually a WebElement in the Selenium backend
576-
select_element = self.find_element(selector_template)
577-
assert isinstance(select_element, WebElement)
580+
select_element = _protocol_to_webelement(self.find_element(selector_template))
578581
select = Select(select_element)
579582
select.select_by_value(value)
580583

0 commit comments

Comments
 (0)