Fix use of _items as a normal trait in PreferencesHelper and PreferencesPage#226
Merged
Conversation
aaronayres35
approved these changes
Nov 23, 2020
Contributor
aaronayres35
left a comment
There was a problem hiding this comment.
Changes LGTM.
The test that sparked my concern here: https://github.com/enthought/apptools/pull/196/files#r526423040 now passes as well. (This scenario covered by the tests added here).
Also this PR description is very clear as to why this fix is possible
Comment on lines
+78
to
+81
| # If we were the one that set the trait (because the underlying | ||
| # preferences node changed) then do nothing. | ||
| if self._is_preference_trait(trait_name): | ||
| self.preferences.set("%s.%s" % (self._get_path(), trait_name), new) |
Contributor
There was a problem hiding this comment.
I do find this comment a little confusing... We are not conditionally doing nothing as it suggests
Contributor
Author
There was a problem hiding this comment.
Good point. I think I know what this means, but I agree this is not obvious at all, I will try to fix this comment.
|
|
||
| # If the change refers to a trait defined on this class, then | ||
| # the trait is not a preference trait and we do nothing. | ||
|
|
Contributor
There was a problem hiding this comment.
This is much clearer, thank you!
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #225
This PR changes the listener for synchronizing the traits on the PreferencesHelper and PreferencesPage with the preferences, such that if the helper / page has a trait with a name suffix
_itemsdefined, it would not be mistaken as the event trait for list/set/dict mutation. Otherwise it would assume it is the event trait for list/set/dict mutation, and handle it specifically. If the assumption is wrong, the change handler will raise an error, but the error will be captured in a normal run condition and the default log message will appear.This fix is possible because one cannot have a trait called
nameand a trait calledname_items(not an event) and expect both of them to operate normally. Consider the following traits-only tests:The above tests pass. If there is a list called "names" and there is a trait called "names_items", the existence of the second trait will cause a lot of unexpected behaviours on its own already.
Checklist