-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[py] Simplified complicated conditional in __convert_to_local_value
function in bidi/script.py
using singledispatchmethod
#15989
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 both are complicated, but the original is better. |
The original nested conditional is really hard to read and trace.. lots of nested indentations.. I feel the new implementation is far more readable and easy to make changes to any specific type in future. Probably I have introduced one more layer of abstraction for maintaining specific type implementation, but it really pays off and reduces maintenance effort in future. |
User description
🔗 Related Issues
💥 What does this PR do?
In this PR, I have simplified the complicated nested conditional statement in
__convert_to_local_value
function inbidi/script.py
usingsingledispatchmethod
.🔧 Implementation Notes
In
singledispatchmethod
the implementation is chosen based on the type of the first argument. If none of type gets matched python will chose to execute default implementation. This implementation makes the code more readable, maintainable and easy to modify in future in case if we have to.💡 Additional Considerations
🔄 Types of changes
PR Type
Other
Description
Refactored complex conditional logic using
singledispatchmethod
Improved code readability and maintainability
Added public
convert_to_local_value
methodChanges diagram
Changes walkthrough 📝
script.py
Refactor value conversion using singledispatchmethod
py/selenium/webdriver/common/bidi/script.py
singledispatchmethod
pattern_SupportedTypes
helper class with type-specific handlersconvert_to_local_value
method for external accesssingledispatchmethod
from functools module