-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[py] Use lazy imports in webdriver __init__.py #16993
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
base: trunk
Are you sure you want to change the base?
Conversation
Replace eager imports of all browser modules with lazy loading via __getattr__. This enables future modularization of the Bazel build and improves import performance for users who only use a subset of browsers. The public API is fully backwards compatible - all existing import patterns continue to work identically. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Latest suggestions up to d3c78b6
Previous suggestions✅ Suggestions up to commit b98c7a6
Suggestions up to commit 81e764b
✅ Suggestions up to commit d758f36
✅ Suggestions up to commit acfa8ca
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR replaces eager imports with lazy loading in the selenium/webdriver/__init__.py module to improve startup performance and enable future Bazel build modularization. The implementation uses Python's PEP 562 module-level __getattr__ to defer imports until attributes are accessed.
Changes:
- Removed 24 eager import statements for browser modules and utilities
- Added lazy import mechanism using
__getattr__with a_LAZY_IMPORTSdictionary mapping - Maintained full backwards compatibility with the public API
2f21aac to
d758f36
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.
|
Persistent suggestions updated to latest commit d3c78b6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
User description
Step 1 in getting Bazel Python to work for us instead of against us
💥 What does this PR do?
Replace eager imports of all browser modules in
py/selenium/webdriver/__init__.pywith lazy loading via__getattr__. This:The public API is fully backwards compatible - all existing import patterns continue to work identically.
🔧 Implementation Notes
Uses Python's
__getattr__module-level function (PEP 562) to defer imports until attributes are actually accessed. This is the standard Python approach for lazy module loading.💡 Additional Considerations
None - this is a drop-in replacement with no behavioral changes to the public API.
🔄 Types of changes
PR Type
Enhancement
Description
Replace eager imports with lazy loading via
__getattr__Improves import performance for subset browser usage
Enables future Bazel build modularization
Maintains full backwards compatibility with public API
Diagram Walkthrough
File Walkthrough
__init__.py
Convert eager imports to lazy loading mechanismpy/selenium/webdriver/init.py
importlibimport for dynamic module loading_LAZY_IMPORTSdictionary mapping public names to modulepaths and attributes
__getattr__function to handle lazy loading on attributeaccess
__dir__function to support introspection of availableattributes
__all__list for explicit public API exports