Skip to content

Conversation

cgoldberg
Copy link
Contributor

@cgoldberg cgoldberg commented Sep 9, 2025

User description

💥 What does this PR do?

This PR converts all relative imports used in the Python bindings to absolute imports and adds a ruff linting rule to disallow them in the future.

Previously, we used a mix of relative and absolute imports. This unifies how we import modules using the preferred method.

🔄 Types of changes

  • Cleanup (formatting, renaming)

PR Type

Other


Description

  • Convert all relative imports to absolute imports

  • Add ruff linting rule to prevent future relative imports

  • Standardize import style across Python bindings


Diagram Walkthrough

flowchart LR
  A["Relative Imports"] --> B["Absolute Imports"]
  B --> C["Ruff Linting Rule"]
  C --> D["Consistent Import Style"]
Loading

File Walkthrough

Relevant files
Formatting
31 files
__init__.py
Convert relative exception imports to absolute                     
+1/-1     
__init__.py
Convert all webdriver relative imports to absolute             
+28/-28 
webdriver.py
Convert chrome options and service imports                             
+2/-3     
action_chains.py
Convert action chain relative imports to absolute               
+5/-6     
action_builder.py
Convert action builder relative imports to absolute           
+7/-8     
interaction.py
Convert input device import to absolute                                   
+1/-1     
key_actions.py
Convert key action relative imports to absolute                   
+5/-5     
key_input.py
Convert key input relative imports to absolute                     
+3/-3     
pointer_actions.py
Convert pointer action relative imports to absolute           
+4/-5     
pointer_input.py
Convert pointer input relative imports to absolute             
+2/-3     
wheel_actions.py
Convert wheel action relative imports to absolute               
+2/-2     
wheel_input.py
Convert wheel input relative imports to absolute                 
+2/-3     
browsing_context.py
Convert session import to absolute                                             
+1/-2     
script.py
Convert log and session imports to absolute                           
+2/-3     
dialog.py
Convert account import to absolute                                             
+1/-1     
webdriver.py
Convert edge options and service imports                                 
+2/-3     
webdriver.py
Convert firefox relative imports to absolute                         
+3/-4     
webdriver.py
Convert IE options and service imports                                     
+2/-3     
fedcm.py
Convert command import to absolute                                             
+1/-1     
mobile.py
Convert command import to absolute                                             
+1/-1     
remote_connection.py
Convert remote module relative imports to absolute             
+4/-5     
shadowroot.py
Convert by and command imports to absolute                             
+2/-2     
switch_to.py
Convert command import to absolute                                             
+1/-2     
webdriver.py
Convert all remote webdriver relative imports                       
+14/-15 
webelement.py
Convert command and shadowroot imports to absolute             
+2/-3     
webdriver.py
Convert safari relative imports to absolute                           
+4/-5     
event_firing_webdriver.py
Convert event listener import to absolute                               
+1/-2     
events.py
Convert support module imports to absolute                             
+2/-2     
ui.py
Convert select and wait imports to absolute                           
+2/-2     
webdriver.py
Convert webkitgtk options and service imports                       
+2/-3     
webdriver.py
Convert wpewebkit options and service imports                       
+2/-3     
Configuration changes
1 files
pyproject.toml
Add TID252 rule to prevent relative imports                           
+1/-1     

@selenium-ci selenium-ci added C-py Python Bindings B-devtools Includes everything BiDi or Chrome DevTools related B-support Issue or PR related to support classes labels Sep 9, 2025
Copy link
Contributor

qodo-merge-pro bot commented Sep 9, 2025

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Lint Rule Scope

Adding ruff rule TID252 enforces absolute imports across the codebase; confirm this does not unintentionally affect third-party test fixtures, examples, or generated files that may rely on relative imports.

extend-select = ["E4", "E7", "E9", "F", "I", "E501", "RUF022", "TID252"]
fixable = ["ALL"]
Public API Consistency

Absolute import changes should preserve the public API surface; verify all and import side effects remain identical, especially aliases like SafariOptions and ChromiumEdge.

from selenium.webdriver.chrome.options import Options as ChromeOptions  # noqa
from selenium.webdriver.chrome.service import Service as ChromeService  # noqa
from selenium.webdriver.chrome.webdriver import WebDriver as Chrome  # noqa
from selenium.webdriver.common.action_chains import ActionChains  # noqa
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities  # noqa
from selenium.webdriver.common.keys import Keys  # noqa
from selenium.webdriver.common.proxy import Proxy  # noqa
from selenium.webdriver.edge.options import Options as EdgeOptions  # noqa
from selenium.webdriver.edge.service import Service as EdgeService  # noqa
from selenium.webdriver.edge.webdriver import WebDriver as ChromiumEdge  # noqa
from selenium.webdriver.edge.webdriver import WebDriver as Edge  # noqa
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile  # noqa
from selenium.webdriver.firefox.options import Options as FirefoxOptions  # noqa
from selenium.webdriver.firefox.service import Service as FirefoxService  # noqa
from selenium.webdriver.firefox.webdriver import WebDriver as Firefox  # noqa
from selenium.webdriver.ie.options import Options as IeOptions  # noqa
from selenium.webdriver.ie.service import Service as IeService  # noqa
from selenium.webdriver.ie.webdriver import WebDriver as Ie  # noqa
from selenium.webdriver.remote.webdriver import WebDriver as Remote  # noqa
from selenium.webdriver.safari.options import Options as SafariOptions
from selenium.webdriver.safari.service import Service as SafariService  # noqa
from selenium.webdriver.safari.webdriver import WebDriver as Safari  # noqa
from selenium.webdriver.webkitgtk.options import Options as WebKitGTKOptions  # noqa
from selenium.webdriver.webkitgtk.service import Service as WebKitGTKService  # noqa
from selenium.webdriver.webkitgtk.webdriver import WebDriver as WebKitGTK  # noqa
from selenium.webdriver.wpewebkit.options import Options as WPEWebKitOptions  # noqa
from selenium.webdriver.wpewebkit.service import Service as WPEWebKitService  # noqa
from selenium.webdriver.wpewebkit.webdriver import WebDriver as WPEWebKit  # noqa
Circular Import Risk

Converting intra-package relative imports to absolute can expose latent circular dependencies; ensure ActionChains and actions.* modules import without recursion in all entry points.

from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.key_input import KeyInput
from selenium.webdriver.common.actions.pointer_input import PointerInput
from selenium.webdriver.common.actions.wheel_input import ScrollOrigin, WheelInput
from selenium.webdriver.common.utils import keys_to_typing
from selenium.webdriver.remote.webelement import WebElement

@SeleniumHQ SeleniumHQ deleted a comment from selenium-ci Sep 9, 2025
@cgoldberg cgoldberg removed B-devtools Includes everything BiDi or Chrome DevTools related B-support Issue or PR related to support classes labels Sep 9, 2025

This comment was marked as off-topic.

Copy link
Member

@navin772 navin772 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cgoldberg cgoldberg merged commit fde053a into SeleniumHQ:trunk Sep 10, 2025
4 checks passed
@cgoldberg cgoldberg deleted the py-convert-relative-imports branch September 10, 2025 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants