summaryrefslogtreecommitdiffstats
path: root/Lib/sets.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-08-15 21:17:04 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-08-15 21:17:04 (GMT)
commitee562fc0846f40aa72c2cbb13983ac2882c0b6ee (patch)
tree121462510ecc964c5fadb60ec6bf6cac6ec85363 /Lib/sets.py
parent98cad48171dd760e2d05fde320e87dad42bd5399 (diff)
downloadcpython-ee562fc0846f40aa72c2cbb13983ac2882c0b6ee.zip
cpython-ee562fc0846f40aa72c2cbb13983ac2882c0b6ee.tar.gz
cpython-ee562fc0846f40aa72c2cbb13983ac2882c0b6ee.tar.bz2
Make sets.py compatible with Py2.2
Diffstat (limited to 'Lib/sets.py')
-rw-r--r--Lib/sets.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/Lib/sets.py b/Lib/sets.py
index ebe62c6..32eb0aa 100644
--- a/Lib/sets.py
+++ b/Lib/sets.py
@@ -54,9 +54,27 @@ what's tested is actually `z in y'.
# - Raymond Hettinger added a number of speedups and other
# improvements.
+from __future__ import generators
+try:
+ from itertools import ifilter, ifilterfalse
+except ImportError:
+ # Code to make the module run under Py2.2
+ def ifilter(predicate, iterable):
+ if predicate is None:
+ def predicate(x):
+ return x
+ for x in iterable:
+ if predicate(x):
+ yield x
+ def ifilterfalse(predicate, iterable):
+ if predicate is None:
+ def predicate(x):
+ return x
+ for x in iterable:
+ if not predicate(x):
+ yield x
__all__ = ['BaseSet', 'Set', 'ImmutableSet']
-from itertools import ifilter, ifilterfalse
class BaseSet(object):
"""Common base class for mutable and immutable sets."""