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
Preferences are currently written the first time a PreferencesHelper for those preferences is created. This leads to some surprising behaviour, especially in scoped preferences. Here's an example test case that currently fails:
deftest_preferences_not_written_on_helper_creation(self):
classAppPreferencesHelper(PreferencesHelper):
#: The node that contains the preferences.preferences_path="app"#: The user's favourite colourcolor=Str()
default_preferences=Preferences(name="default")
default_preferences.set("app.color", "red")
application_preferences=Preferences(name="application")
preferences=ScopedPreferences(
scopes=[application_preferences, default_preferences]
)
self.assertIsNone(application_preferences.get("app.color"))
# Then creation of the helper should not cause the application# preferences to change.AppPreferencesHelper(preferences=preferences)
self.assertIsNone(application_preferences.get("app.color"))
This test case fails at the second self.assertIsNotNone line: the preferences from the default scope have been written into the application scope.
The text was updated successfully, but these errors were encountered:
This PR fixes the `PreferencesHelper` to avoid writing to the
preferences the first time a helper is created for a given `Preferences`
object.
The issue was that on creation, `PreferencesHelper._initialize` was
being called twice: once with `notify=False` and again with
`notify=True`, as a result of the listener to the `preferences` trait.
This PR avoids the second call by making that listener only run post
creation (using `post_init=True`).
Closes#342Closes#74
Preferences are currently written the first time a
PreferencesHelper
for those preferences is created. This leads to some surprising behaviour, especially in scoped preferences. Here's an example test case that currently fails:This test case fails at the second
self.assertIsNotNone
line: the preferences from the default scope have been written into the application scope.The text was updated successfully, but these errors were encountered: