-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
[py] Add type stubs for lazy imported classes and modules #17165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
2e838e5
[py] Add type stubs for selenium.webdriver and stub generator script
cgoldberg 26f9b4f
Merge branch 'trunk' into py-type-stubs
cgoldberg 15e572c
Add to BUILD.bazel
cgoldberg 48e3cfe
Refactored approach using forward references
cgoldberg e114305
Add ruff noqa
cgoldberg c6e4b4a
Fix quotes
cgoldberg f6a332e
Fix heading
cgoldberg 48ede22
Fix script spacing
cgoldberg 0c82afb
Fix bazel
cgoldberg ee62049
Fix bazel
cgoldberg a43d994
Fix generator
cgoldberg 3c36ced
Fix generator
cgoldberg ce5cc92
Use new pyi
cgoldberg 1db212c
Remove generator and just use a static file
cgoldberg 6772c14
Fix
cgoldberg c248c49
Include type stubs in pyproject.toml for building from sdist
cgoldberg f0f0ee2
Remove forward references
cgoldberg 67d8961
Add submodules
cgoldberg 730a11c
Fix formatting
cgoldberg a9e20e1
Fix imports
cgoldberg 4dab62e
Fix imports
cgoldberg c95eb0b
Add __all__ for wildcard imports
cgoldberg 01c4482
Remove unused import
cgoldberg 2a19cf7
Merge branch 'trunk' into py-type-stubs
cgoldberg b996af5
Merge branch 'trunk' into py-type-stubs
cgoldberg be3ffc3
Merge branch 'SeleniumHQ:trunk' into py-type-stubs
cgoldberg dce891a
Merge branch 'trunk' into py-type-stubs
cgoldberg 9352923
Merge branch 'trunk' into py-type-stubs
cgoldberg bcdcd16
Merge branch 'trunk' into py-type-stubs
cgoldberg 25187f5
Add the rest of the missing type stubs
cgoldberg 08082e3
Consolidate imports
cgoldberg d17a05a
Add to bazel and remove redundant aliases
cgoldberg 028beaa
Use relative names for modules and add to exposed names
cgoldberg c047989
Merge branch 'SeleniumHQ:trunk' into py-type-stubs
cgoldberg 406716c
Fix formatting
cgoldberg b2c067f
Merge branch 'trunk' into py-type-stubs
cgoldberg 9549484
Merge branch 'trunk' into py-type-stubs
cgoldberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
|
|
||
| """Generate selenium/webdriver/__init__.pyi from the runtime lazy imports.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import importlib | ||
| from pathlib import Path | ||
|
|
||
| PACKAGE = "selenium.webdriver" | ||
| OUTPUT_FILE = Path(__file__).resolve().parent / "selenium" / "webdriver" / "__init__.pyi" | ||
|
|
||
|
|
||
| def main() -> None: | ||
| pkg = importlib.import_module(PACKAGE) | ||
|
|
||
| lazy_imports: dict[str, tuple[str, str]] = getattr(pkg, "_LAZY_IMPORTS") | ||
| lazy_submodules: dict[str, str] = getattr(pkg, "_LAZY_SUBMODULES") | ||
|
|
||
|
qodo-code-review[bot] marked this conversation as resolved.
Outdated
|
||
| lines: list[str] = [] | ||
| lines.append("# This file is auto-generated. DO NOT EDIT.") | ||
| lines.append("# Generated by py/generate_webdriver_stub.py") | ||
| lines.append("# ruff: noqa: F401, I001") | ||
| lines.append("") | ||
|
|
||
| # Generate re-exported symbols | ||
| for public_name in sorted(lazy_imports): | ||
| module_path, attr_name = lazy_imports[public_name] | ||
|
|
||
| if public_name == attr_name: | ||
| line = f"from {module_path} import {attr_name}" | ||
| else: | ||
| line = f"from {module_path} import {attr_name} as {public_name}" | ||
|
|
||
| lines.append(line) | ||
|
|
||
| lines.append("") | ||
|
|
||
| # Generate submodule re-exports | ||
| if lazy_submodules: | ||
| lines.append("from . import (") | ||
| for name in sorted(lazy_submodules): | ||
| lines.append(f" {name},") | ||
| lines.append(")") | ||
| lines.append("") | ||
|
|
||
| lines.append("__all__: list[str]") | ||
|
|
||
| OUTPUT_FILE.write_text("\n".join(lines) + "\n", encoding="utf-8") | ||
|
|
||
| print(f"Stub written to: {OUTPUT_FILE}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # This file is auto-generated. DO NOT EDIT. | ||
| # Generated by py/generate_webdriver_stub.py | ||
| # ruff: noqa: F401, I001 | ||
|
|
||
| from selenium.webdriver.common.action_chains import ActionChains | ||
| from selenium.webdriver.chrome.webdriver import WebDriver as Chrome | ||
| from selenium.webdriver.chrome.options import Options as ChromeOptions | ||
| from selenium.webdriver.chrome.service import Service as ChromeService | ||
| from selenium.webdriver.edge.webdriver import WebDriver as ChromiumEdge | ||
| from selenium.webdriver.common.desired_capabilities import DesiredCapabilities | ||
| from selenium.webdriver.edge.webdriver import WebDriver as Edge | ||
| from selenium.webdriver.edge.options import Options as EdgeOptions | ||
| from selenium.webdriver.edge.service import Service as EdgeService | ||
| from selenium.webdriver.firefox.webdriver import WebDriver as Firefox | ||
| from selenium.webdriver.firefox.options import Options as FirefoxOptions | ||
| from selenium.webdriver.firefox.firefox_profile import FirefoxProfile | ||
| from selenium.webdriver.firefox.service import Service as FirefoxService | ||
| from selenium.webdriver.ie.webdriver import WebDriver as Ie | ||
| from selenium.webdriver.ie.options import Options as IeOptions | ||
| from selenium.webdriver.ie.service import Service as IeService | ||
| from selenium.webdriver.common.keys import Keys | ||
| from selenium.webdriver.common.proxy import Proxy | ||
| from selenium.webdriver.remote.webdriver import WebDriver as Remote | ||
| from selenium.webdriver.safari.webdriver import WebDriver as Safari | ||
| from selenium.webdriver.safari.options import Options as SafariOptions | ||
| from selenium.webdriver.safari.service import Service as SafariService | ||
| from selenium.webdriver.wpewebkit.webdriver import WebDriver as WPEWebKit | ||
| from selenium.webdriver.wpewebkit.options import Options as WPEWebKitOptions | ||
| from selenium.webdriver.wpewebkit.service import Service as WPEWebKitService | ||
| from selenium.webdriver.webkitgtk.webdriver import WebDriver as WebKitGTK | ||
| from selenium.webdriver.webkitgtk.options import Options as WebKitGTKOptions | ||
| from selenium.webdriver.webkitgtk.service import Service as WebKitGTKService | ||
|
|
||
| from . import ( | ||
| chrome, | ||
| chromium, | ||
| common, | ||
| edge, | ||
| firefox, | ||
| ie, | ||
| remote, | ||
| safari, | ||
| support, | ||
| webkitgtk, | ||
| wpewebkit, | ||
| ) | ||
|
|
||
| __all__: list[str] | ||
|
qodo-code-review[bot] marked this conversation as resolved.
Outdated
qodo-code-review[bot] marked this conversation as resolved.
Outdated
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.