selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[🐛 Bug]: with-as statement and type of WebDriver

Open pinterior opened this issue 9 months ago â€ĸ 2 comments

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.

https://github.com/SeleniumHQ/selenium/blob/6b412e825cfd44e327e44981807d52183d5b6595/py/selenium/webdriver/remote/webdriver.py#L282-L283

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.

https://github.com/SeleniumHQ/selenium/blob/126f156aeef74660a72fa77efffc78adb1353620/py/selenium/webdriver/remote/webdriver.py#L276-L277

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

pinterior avatar Mar 03 '26 13:03 pinterior

@pinterior, thank you for creating this issue. We will troubleshoot it as soon as we can.

Selenium Triage Team: remember to follow the Triage Guide

selenium-ci avatar Mar 03 '26 13:03 selenium-ci

This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Apr 02 '26 22:04 github-actions[bot]