]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Make sets.py compatible with Py2.2
authorRaymond Hettinger <python@rcn.com>
Fri, 15 Aug 2003 21:14:51 +0000 (21:14 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 15 Aug 2003 21:14:51 +0000 (21:14 +0000)
Lib/sets.py
Misc/NEWS

index ebe62c6f17ba2c7d9a24d029c2009b82bee05b40..32eb0aa6f6bca3ebd41954f1b8d2dc4d37d55bd5 100644 (file)
@@ -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."""
index a7b7bc4cea19572effaf5c30dfca65afb4cc22ee..a16679442f54d15fc84f81ed6e170844634a1887 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,8 @@ Extension modules
 Library
 -------
 
+- sets.py can now run under Py2.2
+
 - Bug #778964:  random.seed() now uses fractional seconds so that
   rapid successive, seeding calls will produce different sequences.