-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Fix mypy type errors across service-related files in Selenium WebDriver #15834
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
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
I think type hinting can be useful, but I don't like the idea of forcing type conversions and type checking everywhere just to keep Mypy happy. Python is very much a dynamically typed language that makes heavy use of duck-typing, and most of these changes don't feel "pythonic". I'd be curious to hear what other people think and ideas for how we should better handle type hinting across the codebase. |
Thanks for the input.. So, just to understand, its okay to have type hinting such as: cf9fda4#diff-2f176dbccc5f64167acc6345e2351cab42ccebdefcc77374c69cb9e23b130806R24 However, we don't want to cast every type just to resolve errors like: cf9fda4#diff-b1516e150256fb4a5ef5144d5d8314fc45e92872415ba8900d4cd8d2cc9b9841R70 Or do you think both the type hinting and casting pull away from the dynamic typing of python? In this case I figured at the very least the type hinting would help with better code readability as it explicitly states the types on top of resolving the mypy errors. However, I agree it gets away from the dynamically typed nature of python. If you feel both solutions (casting AND type hinting) aren't useful, we can go ahead and close this PR :) |
User description
🔗 Related Issues
#15697
💥 What does this PR do?
This PR resolves type annotation issues flagged by mypy in various service.py files within the Selenium WebDriver codebase. It ensures compatibility between assigned values and their expected types.
🔧 Implementation Notes
The changes involve explicit type casting and validation to align with the expected types defined in the base classes. This approach was chosen to maintain backward compatibility while resolving type errors.
🔄 Types of changes
PR Type
Bug fix
Description
Fixes mypy type annotation errors across multiple files
Adds explicit type casting and validation for constructor arguments
Ensures correct types in data class factory methods and dictionary conversions
Improves runtime type safety and error handling in service and connection classes
Changes walkthrough 📝
15 files
Fix type annotation for log_output assignment
Enforce type safety for options, service, and executor
Add explicit type conversions in from_dict
Add type conversions and Callable typing for event handlers
Add runtime check for devtools.target in connect_session
Add type conversions in Cookie and CookieFilter methods
Add explicit type for mobile_options and binary_location
Refactor log_output handling for type safety
Add type conversions for socket and key processing
Remove redundant type annotations in Enum subclasses
Add explicit type for browser_name
Add explicit type for extra_commands
Add type checks, casting, and error handling for attributes and
methods
Make DEFAULT_EXECUTABLE_PATH Optional for type safety
Make executable_path Optional in Service constructor