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
Ensure proper type conversion for enum values when retrieving them through the descriptor
The descriptor's get method should return the correct type for login_state. Since it's an Enum value, it should convert the string value to a LoginState enum instance.
-def __get__(self, obj, cls) -> Optional[str]:- return obj._account_data.get(self.name)+def __get__(self, obj, cls) -> Optional[Union[str, LoginState]]:+ value = obj._account_data.get(self.name)+ if self.name == "loginState" and value is not None:+ return LoginState(value)+ return value
Apply this suggestion
Suggestion importance[1-10]: 9
Why: This is a critical fix that ensures type safety and correct behavior. Without this change, the login_state property would return a string instead of the expected LoginState enum value, potentially causing type-related bugs.
9
General
Improve error message clarity by including specific attribute information
The descriptor's set error message should include the attribute name for better debugging.
def __set__(self, obj, value) -> None:
- raise AttributeError("Cannot set readonly attribute")+ raise AttributeError(f"Cannot set readonly attribute '{self.name}'")
Apply this suggestion
Suggestion importance[1-10]: 4
Why: While this improves error message clarity for debugging, it's a minor enhancement that doesn't affect functionality. The current error message is already sufficient for basic error reporting.
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
Moved all getters in fedcm/account.py to
descriptorobjectMotivation and Context
gettersdoing similar job.Types of changes
Checklist
PR Type
enhancement
Description
_AccountDescriptorclass to implement the descriptor pattern for theAccountclass attributes.Accountclass with instances of_AccountDescriptor, simplifying the class structure._AccountDescriptorclass.Changes walkthrough 📝
account.py
Refactor Account class to use descriptor patternpy/selenium/webdriver/common/fedcm/account.py
_AccountDescriptorclass for descriptor pattern._AccountDescriptorinstances.Accountclass by using descriptors for attributes.