# HG changeset patch # User Paul Boddie # Date 1486315084 -3600 # Node ID 529270fc78bdc99cc8c3d5bac5b44eaab6335a92 # Parent 1eb65d050225c357701855bd16b332fd6e2c4f31 Fixed various update operations and expanded the test of sets. diff -r 1eb65d050225 -r 529270fc78bd lib/__builtins__/set.py --- a/lib/__builtins__/set.py Sun Feb 05 18:17:14 2017 +0100 +++ b/lib/__builtins__/set.py Sun Feb 05 18:18:04 2017 +0100 @@ -239,7 +239,7 @@ "Remove from this set all values from 'other'." for value in other: - self.remove(value) + self.discard(value) def discard(self, value): @@ -254,9 +254,14 @@ "Preserve in this set only values in this set found in 'other'." + to_remove = set() + for value in self: if value not in other: - self.remove(value) + to_remove.add(value) + + for value in to_remove: + self.remove(value) def pop(self): diff -r 1eb65d050225 -r 529270fc78bd tests/set.py --- a/tests/set.py Sun Feb 05 18:17:14 2017 +0100 +++ b/tests/set.py Sun Feb 05 18:18:04 2017 +0100 @@ -51,3 +51,20 @@ print 9 in aib # False print 9 in adb # True print 9 in asdb # False +print + +aub2 = a.copy() +aub2.update(b) +print len(aub2) # 6 + +aib2 = a.copy() +aib2.intersection_update(b) +print len(aib2) # 4 + +adb2 = a.copy() +adb2.difference_update(b) +print len(adb2) # 1 + +asdb2 = a.copy() +asdb2.symmetric_difference_update(b) +print len(asdb2) # 2