You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for contributing to Selenium! A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
In this pull request, I have standardized the imports from the typing package to only include the necessary types for type hints.
Motivation and Context
I believe this approach makes the imports more decomposed, readable, and correct. From the changes, you can see that in some files, the entire package was imported as well as specific types.
I consider this coding style inconsistent.
Initially, I started adding type hints and discovered such imports. I will add type hints in one of the following pull requests.
Types of changes
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
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
Type Consistency Ensure that the changes to type hints are consistent throughout the file, especially for the log_output parameter in the __init__ method.
Potential Functionality Change Verify that the changes to the get_cookie method's return type annotation don't affect its functionality or usage elsewhere in the codebase.
Import Order Check if the new import order affects any existing functionality or introduces any circular dependencies.
Latest suggestions up to 597f8f9
Explore these optional code suggestions:
Category
Suggestion
Score
Best practice
Use a tuple instead of a list for immutable sequences
Consider using a tuple instead of a list for the enum attribute in the CdpProperty class, as it appears to be a fixed set of values that won't be modified.
Why: Using a tuple instead of a list for the enum attribute in the CdpProperty class is a good suggestion as it indicates immutability, which can improve code clarity and potentially performance. This change aligns with best practices for handling fixed sets of values.
7
Enhancement
Use keyword-only arguments to improve function call clarity and prevent errors
Consider using keyword-only arguments for the enable_mobile method to improve clarity and prevent potential errors from positional argument misuse.
Why: Introducing keyword-only arguments in the enable_mobile method enhances code clarity and reduces the risk of errors from positional argument misuse. This change is beneficial for maintaining clear and robust code.
6
Utilize TypeAlias for clearer type alias definitions and improved static type checking support
Consider using TypeAlias from typing to define type aliases. This can make the intentions clearer and provide better support for static type checkers.
Why: Using TypeAlias can make the intentions of type aliases clearer and improve static type checking. This change is beneficial for code clarity and maintainability, especially in a shared codebase.
6
Use more specific type hints to improve code clarity and catch potential type-related issues
Consider using a more specific type hint for the actions parameter in the _convert_keys method. Instead of Dict[str, Any], you could use Dict[str, Union[str, int, float, None]] if those are the expected types.
Why: The suggestion to use more specific type hints for the actions parameter in the _convert_keys method can improve code clarity and help catch potential type-related issues. However, it assumes knowledge of the expected types, which may not be accurate without further context.
5
Use a more specific type hint for the capabilities dictionary to improve type checking and documentation
Consider importing TypedDict from typing instead of Dict for more precise type hinting of the default_capabilities method return value. This can provide better type checking and documentation of the expected structure.
Why: The suggestion to use TypedDict instead of Dict for the default_capabilities method return value can enhance type checking and documentation. However, it requires defining a new class and may not be necessary if the dictionary structure is simple or unlikely to change.
5
Implement a more specific type hint for the capabilities dictionary to enhance type checking and documentation
Similar to the WPEWebKit options, consider using TypedDict for more precise type hinting of the default_capabilities method return value. This can provide better type checking and documentation of the expected structure for Safari capabilities.
Why: Similar to the previous suggestion, using TypedDict for the default_capabilities method return value can improve type checking and documentation. It involves additional complexity, which may not be justified if the dictionary structure is straightforward.
5
Refine the type hint for console log arguments to better represent their possible structures
Consider using a more specific type hint for the args attribute in the ConsoleLogEntry class. Instead of List[dict], you could use List[Any] or create a custom type that better represents the structure of the console log arguments.
Why: The suggestion to use List[Any] instead of List[dict] for the args attribute in ConsoleLogEntry is valid but offers marginal improvement. It could be beneficial if the structure of args is not strictly a dictionary, but it reduces specificity.
Why: Adding a type hint to executable_path ensures type consistency across service initializers, which can help avoid potential bugs and improve code clarity.
9
Maintainability
Combine multiple imports from the same module into a single line
Combine the imports from the same module (typing) into a single line to improve readability and maintain consistency.
Why: Combining imports from the same module into a single line improves readability and maintains consistency. However, it is a minor improvement and does not address any critical issues.
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
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.
User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
In this pull request, I have standardized the imports from the typing package to only include the necessary types for type hints.
Motivation and Context
I believe this approach makes the imports more decomposed, readable, and correct. From the changes, you can see that in some files, the entire package was imported as well as specific types.

I consider this coding style inconsistent.
Initially, I started adding type hints and discovered such imports. I will add type hints in one of the following pull requests.
Types of changes
Checklist
PR Type
enhancement
Description
typingpackage across multiple files to improve readability and consistency.typingimports with specific type imports such asOptional,List,Dict,Union, etc.Changes walkthrough 📝
21 files
generate.py
Refactor typing imports for generate.pypy/generate.py
typingimports with specific type imports.Optional,List, etc.castfromtypingdirectly.types.py
Refactor typing imports for types.pypy/selenium/types.py
typingimports with specific type imports.Union,Iterable, etc.service.py
Refactor typing imports for chrome servicepy/selenium/webdriver/chrome/service.py
typingimports with specific type imports.Optional,List, andMapping.service.py
Refactor typing imports for chromium servicepy/selenium/webdriver/chromium/service.py
typingimports with specific type imports.Optional,List, andMapping.pointer_input.py
Refactor typing imports for pointer inputpy/selenium/webdriver/common/actions/pointer_input.py
typingimports with specific type imports.Optional,Dict, andAny.cdp.py
Refactor typing imports for bidi cdppy/selenium/webdriver/common/bidi/cdp.py
typingimports with specific type imports.AsyncGenerator,Generator, andTypeVar.script.py
Refactor typing imports for bidi scriptpy/selenium/webdriver/common/bidi/script.py
typingimports with specific type imports.List.options.py
Refactor typing imports for common optionspy/selenium/webdriver/common/options.py
typingimports with specific type imports.Optional.service.py
Refactor typing imports for common servicepy/selenium/webdriver/common/service.py
typingimports with specific type imports.Optional,Mapping, andUnion.virtual_authenticator.py
Refactor typing imports for virtual authenticatorpy/selenium/webdriver/common/virtual_authenticator.py
typingimports with specific type imports.Optional,Dict, andUnion.service.py
Refactor typing imports for edge servicepy/selenium/webdriver/edge/service.py
typingimports with specific type imports.Optional,List, andMapping.service.py
Refactor typing imports for firefox servicepy/selenium/webdriver/firefox/service.py
typingimports with specific type imports.Optional,List, andMapping.service.py
Refactor typing imports for IE servicepy/selenium/webdriver/ie/service.py
typingimports with specific type imports.OptionalandList.webdriver.py
Refactor typing imports for remote webdriverpy/selenium/webdriver/remote/webdriver.py
typingimports with specific type imports.Optional,Dict, andType.options.py
Refactor typing imports for safari optionspy/selenium/webdriver/safari/options.py
typingimports with specific type imports.Dict.service.py
Refactor typing imports for safari servicepy/selenium/webdriver/safari/service.py
typingimports with specific type imports.Optional,List, andMapping.event_firing_webdriver.py
Refactor typing imports for event firing webdriverpy/selenium/webdriver/support/event_firing_webdriver.py
typingimports with specific type imports.List,Tuple, andAny.wait.py
Refactor typing imports for support waitpy/selenium/webdriver/support/wait.py
typingimports with specific type imports.Optional,Tuple, andType.service.py
Refactor typing imports for webkitgtk servicepy/selenium/webdriver/webkitgtk/service.py
typingimports with specific type imports.Optional,List, andMapping.options.py
Refactor typing imports for wpewebkit optionspy/selenium/webdriver/wpewebkit/options.py
typingimports with specific type imports.Dict.service.py
Refactor typing imports for wpewebkit servicepy/selenium/webdriver/wpewebkit/service.py
typingimports with specific type imports.Optional,List, andMapping.