mypy error "Incompatible return value type" on webdriver.find_element
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 570
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 24
Description
Mypy errors on the fact that appium.webdriver.WebDriver.find_element isn't overridden but indeed returns a different WebElement.
Reproducible Code
# no need to actually run this code, just send it through MyPy to see the error.
from appium.webdriver.common.appiumby import AppiumBy
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from appium.webdriver import Remote
from appium.webdriver.webelement import WebElement
def find_element(driver: Remote) -> WebElement:
# should get a mypy error on next line
return driver.find_element(AppiumBy.ACCESSIBILITY_ID, "demo button")
def find_elements(driver: Remote) -> WebElement:
# should get a mypy error on next line
return driver.find_elements(AppiumBy.ACCESSIBILITY_ID, "demo confetti")
mypy output:
mypy .
screenpy_appium/target.py:89: error: Incompatible return value type (got "selenium.webdriver.remote.webelement.WebElement", expected "appium.webdriver.webelement.WebElement") [return-value]
screenpy_appium/target.py:98: error: Incompatible return value type (got "list[selenium.webdriver.remote.webelement.WebElement]", expected "list[appium.webdriver.webelement.WebElement]") [return-value]
Found 2 errors in 1 file (checked 35 source files)
Solution
Annotations need to be added to appium.webdriver.WebDriver
class WebDriver(
webdriver.Remote,
...
):
if TYPE_CHECKING:
def find_element(self, by=By.ID, value: Optional[str] = None) -> MobileWebElement:
...
def find_elements(self, by=By.ID, value: Optional[str] = None) -> list[MobileWebElement]:
...
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at appium.webdriver.WebDriver and inspect its inherited find_element and find_elements signatures. Run the reproducible snippet through mypy, then verify that the WebDriver annotations produce Appium WebElement return types and the reported return-value errors disappear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100