summaryrefslogtreecommitdiffstats
path: root/Doc/lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-08-17 08:34:09 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-08-17 08:34:09 (GMT)
commit6a1801271aa4011cf26e7a64b52f6be10997f267 (patch)
tree3aaa9dc996dcfd676d809bf585cd498420b3bcbf /Doc/lib
parent236ffba40005039cfbc0bd7475345ef7fedf86c5 (diff)
downloadcpython-6a1801271aa4011cf26e7a64b52f6be10997f267.zip
cpython-6a1801271aa4011cf26e7a64b52f6be10997f267.tar.gz
cpython-6a1801271aa4011cf26e7a64b52f6be10997f267.tar.bz2
Improvements to set.py:
* Relaxed the argument restrictions for non-operator methods. They now allow any iterable instead of requiring a set. This makes the module a little easier to use and paves the way for an efficient C implementation which can take better advantage of iterable arguments while screening out immutables. * Deprecated Set.update() because it now duplicates Set.union_update() * Adapted the tests and docs to include the above changes. * Added more test coverage including testing identities and checking to make sure non-restartable generators work as arguments. Will backport to Py2.3.1 so that the interface remains consistent across versions. The deprecation of update() will be changed to a FutureWarning.
Diffstat (limited to 'Doc/lib')
-rw-r--r--Doc/lib/libsets.tex22
1 files changed, 19 insertions, 3 deletions
diff --git a/Doc/lib/libsets.tex b/Doc/lib/libsets.tex
index 71b6d3d..8551ab6 100644
--- a/Doc/lib/libsets.tex
+++ b/Doc/lib/libsets.tex
@@ -91,6 +91,15 @@ the following operations:
{new set with a shallow copy of \var{s}}
\end{tableiii}
+Note, this non-operator versions of \method{union()},
+\method{intersection()}, \method{difference()}, and
+\method{symmetric_difference()} will accept any iterable as an argument.
+In contrast, their operator based counterparts require their arguments to
+be sets. This precludes error-prone constructions like
+\code{Set('abc') \&\ 'cbs'} in favor of the more readable
+\code{Set('abc').intersection('cbs')}.
+\versionchanged[Formerly all arguments were required to be sets]{2.3.1}
+
In addition, both \class{Set} and \class{ImmutableSet}
support set to set comparisons. Two sets are equal if and only if
every element of each set is contained in the other (each is a subset
@@ -145,12 +154,19 @@ but not found in \class{ImmutableSet}:
\lineiii{\var{s}.pop()}{}
{remove and return an arbitrary element from \var{s}; raises
KeyError if empty}
- \lineiii{\var{s}.update(\var{t})}{}
- {add elements from \var{t} to set \var{s}}
\lineiii{\var{s}.clear()}{}
{remove all elements from set \var{s}}
\end{tableiii}
+\versionchanged[Earlier versions had an \method{update()} method; use
+ \method{union_update()} instead]{2.3.1}
+
+Note, this non-operator versions of \method{union_update()},
+\method{intersection_update()}, \method{difference_update()}, and
+\method{symmetric_difference_update()} will accept any iterable as
+an argument.
+\versionchanged[Formerly all arguments were required to be sets]{2.3.1}
+
\subsection{Example \label{set-example}}
@@ -167,7 +183,7 @@ but not found in \class{ImmutableSet}:
Set(['Jane', 'Marvin', 'Janice', 'John', 'Jack'])
>>> employees.issuperset(engineers) # superset test
False
->>> employees.update(engineers) # update from another set
+>>> employees.union_update(engineers) # update from another set
>>> employees.issuperset(engineers)
True
>>> for group in [engineers, programmers, management, employees]: