-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Description
Issue:
The function signature and type hint for selenium.webdriver.remote.webdriver.WebDriver.__init__
currently define the options
parameter as optional:
options: Optional[Union[BaseOptions, list[BaseOptions]]] = None, |
However, the body of the function immediately raises a TypeError
if options
is not provided. This means the signature is inconsistent with the implementation. The consequence is that static type checkers (like Mypy) will not flag a missing options
argument as an error, and developers reading the code will be misled, pushing a preventable bug to runtime.
Expected behavior:
The function signature should be updated to reflect that the options
parameter is mandatory. The Optional[...
] wrapper and the = None
default value should be removed.
This will allow static analysis tools to correctly identify missing options
arguments at development time and will make the API contract clear to developers.
Minimal, Reproducible Example
from selenium import webdriver
# According to the current type hint, this is valid code.
# A static type checker will not report an error.
driver = webdriver.Remote(command_executor="http://127.0.0.1:4444")
# However, running this code raises a TypeError because `options` is mandatory.
Environment
- OS: All
- Selenium Version: 4.x (main/trunk branch)
- Python Version: All
Suggested Fix
The function signature should be changed to remove the default None
value and the Optional
type hint, making the parameter correctly appear as mandatory to both developers and static analysis tools.