feat(State): Implement __delitem__
and pop
methods for element removal
#1856
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.
feat(State): Implement
__delitem__
andpop
methods for element removalWhy?
The
State
class is designed to manage state and should mimic the behavior of a standard Python dictionary (dict
). However, it previously lacked standard methods for element removal, such asdel state[key]
andstate.pop(key)
.This PR addresses this gap by making the
State
class more convenient and consistent with standard Python conventions.What does this change do? (Implementation Details)
This PR introduces two standard dictionary-like removal methods to the
State
class:Implemented
__delitem__(self, key)
:del state[key]
syntax.self._value
andself._delta
) to ensure state consistency.KeyError
if the key does not exist, fully replicating the behavior of a standarddict
.Implemented
pop(self, key, default=...)
:.pop()
method, which removes a key and returns its corresponding value.default
argument to prevent aKeyError
when the key is not found.__getitem__
and__delitem__
.How to use it? (Usage Examples)
Unit-tests have been passed
Code auto-format has been passed
Tested on my own and works perfectly. Small but useful addition for more flexible state management