Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/ClusterShell/NodeSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
from ClusterShell.RangeSet import RangeSetParseError


# Python 3 compatibility
# Python 2 compat: basestring alias, drop this block when py2 support ends (1.11)
try:
basestring
except NameError:
Expand Down Expand Up @@ -712,10 +712,13 @@ def __sub__(self, other):
return NotImplemented
return self.difference(other)

def difference_update(self, other, strict=False):
def difference_update(self, other, purge=True, strict=False):
"""
``s.difference_update(t)`` removes from s all the elements found in t.

If purge is False, patterns emptied by the operation are kept as
empty entries instead of being removed.

:raises KeyError: an element cannot be removed (only if strict is
True)
"""
Expand All @@ -740,8 +743,9 @@ def difference_update(self, other, strict=False):
elif strict:
raise KeyError(pat)

for pat in purge_patterns:
del self._patterns[pat]
if purge:
for pat in purge_patterns:
del self._patterns[pat]

def __isub__(self, other):
"""
Expand Down