Skip to content

[馃悰 Bug]: with-as statement and type of WebDriver聽#17169

Description

@pinterior

Description

in selenium <= 4.38.0, WebDriver.__enter__ did not have a return type annotation.
so type checker with return type inference (e.g. pyright) were able to infer drv in the code below as selenium.webdriver.chrome.webdriver.WebDriver.

def __enter__(self):
return self

however in 4.39.0, type hint that says the return type is selenium.webdriver.remote.webdriver.WebDriver was added.
as a result, some browser specific method (e.g. get_log) started causing type errors.

def __enter__(self) -> "WebDriver":
return self

Reproducible Code

from typing import reveal_type
from selenium.webdriver.chrome.webdriver import WebDriver

reveal_type(WebDriver().get_log)

with WebDriver() as drv:
    reveal_type(drv.get_log)

鈩癸笍 Last known working version: 4.38.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-pyPython BindingsI-defectSomething is not working as intendedI-regressionSomething was working but we "fixed" it

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions