-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
WIP Eventful dict and custom events #278
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
# void functions used as a callback placeholders. | ||
def _default_pre_set(self, key, value): | ||
return value | ||
|
||
def _default_post_set(self, key, value): | ||
pass | ||
|
||
def _default_pre_del(self, key): | ||
pass | ||
|
||
def _default_post_del(self, key): | ||
pass | ||
|
||
|
||
class edict(dict): | ||
|
||
pre_set = _default_pre_set | ||
post_set = _default_post_set | ||
pre_del = _default_pre_del | ||
post_del = _default_post_del | ||
|
||
def pop(self, key): | ||
self.pre_del(key) | ||
ret = dict.pop(self, key) | ||
self.post_del(key) | ||
return ret | ||
|
||
def popitem(self): | ||
key = next(iter(self)) | ||
return key, self.pop(key) | ||
|
||
def update(self, other_dict): | ||
for (key, value) in other_dict.items(): | ||
self[key] = value | ||
|
||
def clear(self): | ||
for key in list(self.keys()): | ||
del self[key] | ||
|
||
def __setitem__(self, key, value): | ||
value = self.pre_set(key, value) | ||
ret = dict.__setitem__(self, key, value) | ||
self.post_set(key, value) | ||
return ret | ||
|
||
def __delitem__(self, key): | ||
value = self.pre_del(key) | ||
ret = dict.__delitem__(self, key) | ||
value = self.post_del(key) | ||
return ret | ||
|
This file contains 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
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail in the case that a default value was defined via
TraitType.__init__
since those are only assigned to theHasTraits
instance duringinstance_init
. I'm not sure this can be resolved given the current way default values are handled. However with #332, popping off of_trait_values
would work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue resolved - #322 was merged.