Fix complete_elements in DADict/DASet and add cancel_add_or_edit to DADict #879
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.
I'm sorry that this PR does more than one thing.
First, it fixes the
complete_elementsmethods ofDADictandDASetto return a new instance of their class with the complete_elements, rather than returning a genericdictorset. This matches the behavior of the method in aDAListand gives access to all of the DA methods included expected string output.Second, it adds the
cancel_add_or_editmethod toDADict. This is very similar to theDAListversion it is based on, but handles deleting thenew_item_nameattribute and usespopitemto remove the last item from the dict.Third, it fixes the logic in
DAList'scancel_add_or_editmethod to onlypopthe last item ifself.complete_elements().number()is less thanself.number_gathered()rather than only if they are unequal. This is just a safety net for the (maybe not even possible) edge case where the length ofcomplete_elementsis somehow bigger thannumber_gathered, in which case you can't know if you want to pop the last element off of theDAList. I wrote theDADictversion using this same logic. In all normal cases this works as expected and the same as with!=.