Skip to content

Conversation

@cgoldberg
Copy link
Member

@cgoldberg cgoldberg commented May 23, 2025

User description

💥 What does this PR do?

This PR fixes many type hint issues and upgrades them to be Python 3.9+ syntax compliant (moving many data types to use collections.abc)

🔄 Types of changes

  • Cleanup (formatting, renaming)
  • Bug fix (backwards compatible)
  • No functional changes

PR Type

Bug fix, Enhancement


Description

  • Upgrade type hints to Python 3.9+ syntax throughout codebase

  • Replace legacy List, Dict, Tuple, etc. with built-in generics (e.g., list, dict, tuple)

  • Move type hints to use collections.abc where appropriate

  • Remove unused or redundant imports for cleaner code


Changes walkthrough 📝

Relevant files
Enhancement
48 files
exceptions.py
Update Sequence import to use collections.abc                       
+2/-1     
types.py
Use collections.abc.Iterable and update type hints             
+3/-2     
service.py
Use built-in generics and collections.abc.Mapping               
+3/-2     
options.py
Replace List/Dict with list/dict in type hints                     
+6/-6     
service.py
Use collections.abc.Mapping and update type hints               
+4/-3     
action_builder.py
Replace List with list in type hints                                         
+3/-3     
input_device.py
Use list instead of List for actions attribute                     
+2/-2     
interaction.py
Use dict instead of Dict for encode method                             
+2/-2     
pointer_input.py
Use dict instead of Dict for _convert_keys                             
+2/-2     
browser.py
Remove unused imports and update type hints to list/dict 
+3/-4     
browsing_context.py
Replace Dict/List with dict/list in type hints                     
+25/-25 
cdp.py
Use collections.abc for async generators and iterators     
+4/-4     
common.py
Use dict instead of Dict for command_builder                         
+1/-3     
log.py
Use list instead of List for args type hint                           
+1/-2     
storage.py
Replace Dict/List with dict/list in type hints                     
+12/-12 
webextension.py
Use dict instead of Dict in type hints                                     
+3/-3     
by.py
Use dict instead of Dict for _custom_finders                         
+2/-2     
dialog.py
Use list instead of List for get_accounts return type       
+2/-2     
log.py
Use collections.abc.AsyncGenerator and update type hints 
+7/-6     
options.py
Use list instead of List for _arguments                                   
+2/-2     
print_page_options.py
Use list/dict instead of List/Dict/Tuple in type hints     
+5/-5     
selenium_manager.py
Use list instead of List for args and log_items                   
+4/-4     
service.py
Use collections.abc.Mapping and update type hints               
+3/-2     
timeouts.py
Use dict instead of Dict for JSONTimeouts                               
+1/-3     
utils.py
Use collections.abc.Iterable and list for keys_to_typing 
+4/-3     
virtual_authenticator.py
Use dict instead of Dict for to_dict methods                         
+4/-4     
service.py
Use collections.abc.Mapping and update type hints               
+3/-2     
options.py
Use dict instead of Dict for opts                                               
+2/-2     
service.py
Use collections.abc.Mapping and update type hints               
+4/-3     
options.py
Use dict instead of Dict for _options and _additional       
+3/-3     
service.py
Use list instead of List for service_args                               
+3/-3     
errorhandler.py
Use dict instead of Dict for check_response                           
+3/-3     
fedcm.py
Use list instead of List for account_list                               
+2/-2     
webdriver.py
Use list/dict instead of List/Dict in type hints                 
+10/-10 
webelement.py
Use list instead of List for find_elements                             
+1/-2     
options.py
Use dict instead of Dict for default_capabilities               
+1/-2     
service.py
Use collections.abc.Mapping and update type hints               
+4/-3     
color.py
Use collections.abc.Sequence and update Match import         
+3/-7     
event_firing_webdriver.py
Use list and tuple built-ins in type hints                             
+4/-4     
expected_conditions.py
Use built-in generics for tuple/list in type hints             
+20/-20 
relative_locator.py
Use dict/list instead of Dict/List for LocatorType and filters
+10/-10 
select.py
Use list instead of List for options and all_selected_options
+2/-3     
wait.py
Use tuple instead of Tuple for IGNORED_EXCEPTIONS               
+2/-2     
service.py
Use collections.abc.Mapping and update type hints               
+4/-3     
options.py
Use dict instead of Dict for default_capabilities               
+1/-2     
service.py
Use collections.abc.Mapping and update type hints               
+4/-3     
virtual_authenticator_tests.py
Use list instead of List for credential_id type hint         
+1/-2     
credentials_tests.py
Use tuple instead of Tuple for data fixture                           
+1/-2     
Cleanup
1 files
bidi_webextension_tests.py
Remove redundant pytest import formatting                               
+2/-2     
Bug fix
1 files
remote_downloads_tests.py
Remove explicit encoding in open for text file                     
+1/-1     

Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @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 May 23, 2025
    @selenium-ci
    Copy link
    Member

    Thank you, @cgoldberg for this code suggestion.

    The support packages contain example code that many users find helpful, but they do not necessarily represent
    the best practices for using Selenium, and the Selenium team is not currently merging changes to them.

    We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks.
    If you have any questions, please contact us

    @qodo-merge-pro
    Copy link
    Contributor

    qodo-merge-pro bot commented May 23, 2025

    PR Reviewer Guide 🔍

    (Review updated until commit 9b86e7e)

    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 Conversion

    The keys_to_typing function is using list[str] for return type annotation, but the function might return a list containing both strings and Keys objects. This could lead to type checking errors.

    def keys_to_typing(value: Iterable[AnyKey]) -> list[str]:
        """Processes the values that will be typed in the element."""
        characters: list[str] = []
        for val in value:
    File Mode

    The file open mode was removed when updating the code. While the default mode is 'r' (read), it's better to be explicit for clarity and to prevent future issues if the default behavior changes.

    with open(target_file) as file:
        assert "Hello, World!" in file.read()

    @cgoldberg
    Copy link
    Member Author

    nice try @selenium-ci

    @cgoldberg cgoldberg reopened this May 23, 2025
    @SeleniumHQ SeleniumHQ deleted a comment from qodo-merge-pro bot May 23, 2025
    @cgoldberg cgoldberg added I-enhancement Something could be better and removed B-devtools Includes everything BiDi or Chrome DevTools related B-support Issue or PR related to support classes labels May 23, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    C-py Python Bindings I-enhancement Something could be better Review effort 2/5

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants