[Python-checkins] r54978 - sandbox/trunk/abc/abc.py

guido.van.rossum python-checkins at python.org
Thu Apr 26 02:46:21 CEST 2007


Author: guido.van.rossum
Date: Thu Apr 26 02:46:13 2007
New Revision: 54978

Modified:
   sandbox/trunk/abc/abc.py
Log:
Make Set.clear() a concrete method.


Modified: sandbox/trunk/abc/abc.py
==============================================================================
--- sandbox/trunk/abc/abc.py	(original)
+++ sandbox/trunk/abc/abc.py	Thu Apr 26 02:46:13 2007
@@ -305,12 +305,6 @@
         """Return True if it was deleted, False if not there."""
         raise NotImplementedError
 
-    @abstractmethod
-    def clear(self):
-        """Implementing this would be bad and slow, hence it's abstract."""
-        # XXX It's a pain to have to define this.  Maybe leave out?
-        raise NotImplementedError
-
     def pop(self):
         """Return the popped value.  Raise KeyError if empty."""
         it = iter(self)
@@ -331,6 +325,14 @@
             self.add(value)
             return True
 
+    def clear(self):
+        """This is slow (creates N new iterators!) but effective."""
+        try:
+            while True:
+                self.pop()
+        except KeyError:
+            pass
+
     def __ior__(self, it: Iterable):
         for value in it:
             self.add(value)
@@ -517,6 +519,10 @@
         return False
 
 
+# XXX HashableMapping
+# XXX MutableMapping
+
+
 ### SEQUENCES ###
 
 


More information about the Python-checkins mailing list