Skip to content

[πŸ› Bug]: mypy detects incompatible typesΒ #13544

@kellypilot

Description

@kellypilot

What happened?

When checking types with mypy v1.8.0, incompatible types are detected

url_to_be is declared as
def url_to_be(url: str) -> Callable[[WebDriver], bool]:

but any_of requires other argument type
def any_of(*expected_conditions: Callable[[D], T]) -> Callable[[D], Union[Literal[False], T]]:

How can we reproduce the issue?

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

self.__waiter: WebDriverWait
self.__data_url: str

elements = self.__waiter.until(
    EC.any_of(
        EC.visibility_of_any_elements_located((
            By.CSS_SELECTOR,
            "p.3yeW3"
        )),
        # mypy error: Argument 2 to "any_of" has incompatible type
        # "Callable[[WebDriver], bool]";
        # expected "Callable[[Any], Literal[False] | list[WebElement] | WebElement]"
        EC.url_to_be(self.__data_url)
    )
)

Relevant log output

error: Argument 2 to "any_of" has incompatible type "Callable[[WebDriver], bool]"; expected "Callable[[Any], Literal[False] | list[WebElement] | WebElement]"  [arg-type]

Operating System

Ubuntu

Selenium version

4.17.2

What are the browser(s) and version(s) where you see this issue?

does not matter

What are the browser driver(s) and version(s) where you see this issue?

does not matter

Are you using Selenium Grid?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!C-pyPython BindingsR-help wantedIssues looking for contributions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions