[Python-checkins] r54977 - peps/trunk/pep-3119.txt
guido.van.rossum
python-checkins at python.org
Thu Apr 26 02:44:41 CEST 2007
Author: guido.van.rossum
Date: Thu Apr 26 02:44:37 2007
New Revision: 54977
Modified:
peps/trunk/pep-3119.txt
Log:
Make clear() a concrete method that calls pop() until it raises KeyError.
Modified: peps/trunk/pep-3119.txt
==============================================================================
--- peps/trunk/pep-3119.txt (original)
+++ peps/trunk/pep-3119.txt Thu Apr 26 02:44:37 2007
@@ -407,14 +407,6 @@
was present and ``False`` if it wasn't. The abstract
implementation raises ``NotImplementedError``.
- ``.clear()``
- Abstract method that empties the set. The abstract
- implementation raises ``NotImplementedError``. (Making this
- concrete would just add a slow, cumbersome default
- implementation.) **Open issues:** Forcing every mutable set
- to implement this may be a pain for such a fairly
- non-essential method. Perhaps just drop it?
-
``.pop()``
Concrete method that removes an arbitrary item. If the set is
empty, it raises ``KeyError``. The default implementation
@@ -426,6 +418,14 @@
return ``True`` if ``x`` was added, ``False`` if it was
removed.
+ ``.clear()``
+ Concrete method that empties the set. The default
+ implementation repeatedly calls ``self.pop()`` until
+ ``KeyError`` is caught. (Note: this is probably much slower
+ than simply creating a new set, even if an implementation
+ overrides it with a faster approach; but in some cases object
+ identity is important.)
+
This also supports the in-place mutating operations ``|=``,
``&=``, ``^=``, ``-=``. These are concrete methods whose right
operand can be an arbitrary ``Iterable``, except for ``&=``, whose
@@ -491,8 +491,8 @@
``MutableMapping``
A subclass of ``Mapping`` that also implements some standard
mutating methods. Abstract methods include ``__setitem__``,
- ``__delitem__``, ``clear``, ``update``. Concrete methods include
- ``pop``, ``popitem``. Note: ``setdefault`` is *not* included.
+ ``__delitem__``. Concrete methods include ``pop``, ``popitem``,
+ ``clear``, ``update``. Note: ``setdefault`` is *not* included.
**Open issues:**
More information about the Python-checkins
mailing list