appium / appium/python-client

mypy error "Incompatible return value type" on webdriver.find_element

Abierto
#1,147 7 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
1.8k
Forks
570
Merge medio
1 d 10 h
PR fusionados (30 d)
24

Descripción

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]:
            ...

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza en appium.webdriver.WebDriver e inspecciona las firmas heredadas de find_element y find_elements. Ejecuta el fragmento reproducible con mypy y, a continuación, verifica que las anotaciones de WebDriver produzcan tipos de retorno Appium WebElement y que desaparezcan los errores return-value informados.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
mobile-dev
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
55/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.