[Commits] (pje) Spike: don't issue events for items removed from a
set that are added right
commits at osafoundation.org
commits at osafoundation.org
Tue Feb 15 16:36:35 PST 2005
Commit by: pje
Modified files:
internal/Spike/src/spike/models.py 1.2 1.3
internal/Spike/src/spike/models.txt 1.2 1.3
Log message:
Spike: don't issue events for items removed from a set that are added right
back, and use repr() to display items that failed a type check.
ViewCVS links:
http://cvs.osafoundation.org/index.cgi/internal/Spike/src/spike/models.py.diff?r1=text&tr1=1.2&r2=text&tr2=1.3
http://cvs.osafoundation.org/index.cgi/internal/Spike/src/spike/models.txt.diff?r1=text&tr1=1.2&r2=text&tr2=1.3
Index: internal/Spike/src/spike/models.py
diff -u internal/Spike/src/spike/models.py:1.2 internal/Spike/src/spike/models.py:1.3
--- internal/Spike/src/spike/models.py:1.2 Tue Feb 15 15:33:09 2005
+++ internal/Spike/src/spike/models.py Tue Feb 15 16:36:34 2005
@@ -49,7 +49,7 @@
if not isinstance(ob,t):
if t:
raise TypeError(
- "%s is not of type %s" % (ob,self._typeName(t))
+ "%r is not of type %s" % (ob,self._typeName(t))
)
else:
raise TypeError("Null set cannot be changed")
@@ -62,7 +62,11 @@
for ob in add:
if ob not in data:
data.append(ob)
- added.append(ob)
+ if ob in removed:
+ removed.remove(ob) # ignore re-add of removed item
+ else:
+ added.append(ob)
+
if removed or added:
try:
SetChanged(self,removed,added)
Index: internal/Spike/src/spike/models.txt
diff -u internal/Spike/src/spike/models.txt:1.2 internal/Spike/src/spike/models.txt:1.3
--- internal/Spike/src/spike/models.txt:1.2 Tue Feb 15 15:33:09 2005
+++ internal/Spike/src/spike/models.txt Tue Feb 15 16:36:34 2005
@@ -132,11 +132,20 @@
>>> s
Set([10])
+If you add and remove the same item, however, it doesn't show up in the change
+event::
+
+ >>> s.replace(remove=[10],add=[10, 5])
+ <Change for Set([10, 5]): removed=[], added=[5]>
+
+ >>> s.replace(remove=[10],add=[10]) # no-op
+
+
And you can also use the ``reset()`` method to clear the set's contents, and
optionally supply an iterable of new contents::
>>> s.reset([1,2,3])
- <Change for Set([1, 2, 3]): removed=[10], added=[1, 2, 3]>
+ <Change for Set([1, 2, 3]): removed=[5, 10], added=[1, 2, 3]>
>>> s
Set([1, 2, 3])
More information about the Commits
mailing list