diff options
author | Raymond Hettinger <python@rcn.com> | 2008-05-08 17:18:13 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-05-08 17:18:13 (GMT) |
commit | f8105ceec7c9e97dc46bde392f5e1e46ccc02d1a (patch) | |
tree | 63a988a12e882a8584fc8f2165382d004315cf7b | |
parent | bf5bd9f2f06ed07cd724dbc89980744f0ab1689b (diff) | |
download | cpython-f8105ceec7c9e97dc46bde392f5e1e46ccc02d1a.zip cpython-f8105ceec7c9e97dc46bde392f5e1e46ccc02d1a.tar.gz cpython-f8105ceec7c9e97dc46bde392f5e1e46ccc02d1a.tar.bz2 |
Issue 2778. Document the temporary frozenset swap in __contains__(), remove(), and discard().
-rw-r--r-- | Doc/library/stdtypes.rst | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 85438e0..f04b4b9 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1585,7 +1585,7 @@ proper superset of the second set (is a superset, but is not equal). Instances of :class:`set` are compared to instances of :class:`frozenset` based on their members. For example, ``set('abc') == frozenset('abc')`` returns -``True``. +``True`` and so does ``set('abc') in set([frozenset('abc')])``. The subset and equality comparisons do not generalize to a complete ordering function. For example, any two disjoint sets are not equal and are not subsets @@ -1624,18 +1624,18 @@ apply to immutable instances of :class:`frozenset`: Update the set, keeping only elements found in either set, but not in both. -.. method:: set.add(el) +.. method:: set.add(elem) - Add element *el* to the set. + Add element *elem* to the set. -.. method:: set.remove(el) +.. method:: set.remove(elem) - Remove element *el* from the set. Raises :exc:`KeyError` if *el* is not + Remove element *elem* from the set. Raises :exc:`KeyError` if *elem* is not contained in the set. -.. method:: set.discard(el) +.. method:: set.discard(elem) - Remove element *el* from the set if it is present. + Remove element *elem* from the set if it is present. .. method:: set.pop() @@ -1652,8 +1652,11 @@ Note, the non-operator versions of the :meth:`update`, :meth:`symmetric_difference_update` methods will accept any iterable as an argument. -The design of the set types was based on lessons learned from the Python -implementation found in the :mod:`sets` module. +Note, the *elem* argument to the :meth:`__contains__`, :meth:`remove`, and +:meth:`discard` methods may be a set. To support searching for an equivalent +frozenset, the *elem* set is temporarily mutated during the search and then +restored. During the search, the *elem* set should not be read or mutated +since it does not have a meaningful value. .. seealso:: |