Add ability to delete items only if they exist from UserDict
This commit is contained in:
parent
8b4612847b
commit
1a459eebf4
@ -314,6 +314,12 @@ class UserDict(dict):
|
||||
value.dict_values.append(self)
|
||||
|
||||
def __delitem__(self, item):
|
||||
if isinstance(item, slice): # special-case: delete if it exists, otherwise don't
|
||||
if item.start is item.step is None: # checks out
|
||||
item = item.stop
|
||||
if item not in self:
|
||||
return
|
||||
|
||||
value = self[item]
|
||||
super().__delitem__(item)
|
||||
if isinstance(item, User):
|
||||
|
Loading…
Reference in New Issue
Block a user