Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta
#1,147 7 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 3 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
55/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
python
Domínio
mobile-dev

Direção de pesquisa

Comece em appium.webdriver.WebDriver e inspecione as assinaturas herdadas de find_element e find_elements. Execute o snippet reproduzível com mypy e, em seguida, verifique se as anotações de WebDriver produzem tipos de retorno Appium WebElement e se os erros return-value relatados desaparecem.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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]:
            ...
Linguagem predominante
Python
Estrelas
1.8k
Forks
570
Merge médio
1d 10h
PRs com merge (30d)
24

Preparar o ambiente

Ainda não verificamos os arquivos de configuração deste projeto. Comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de appium/python-client

Todas as issues de appium/python-client

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.