Backported sets module for 2.2.x

Mike C. Fletcher mcfletch at rogers.com
Fri Mar 14 18:35:12 EST 2003


Since the sets module is a rather nifty little module, I've "ported" it 
from the Python 2.3a2 Lib package back to Python 2.2.x . Translation was 
fairly minimal, mostly duplicating the ifilter and ifilterfalse 
operation and hacking up the test framework somewhat to run without 
being part of the test package (and to allow for the True/False versus 
1/0 differences).

I also made the "cases" attribute of the TestSubsetNonOverlap test use 
an explicit tuple, rather than relying on Python 2.3's string in string 
operation to work for the bare string.

With the minimally-hacked test suite, w/ Python 2.2.2 on Win2Kall tests 
pass.

Enjoy all,
Mike

P:\backports>diff -b c:\bin\lang\py23\Lib\sets.py sets.py
42a43,55
 > ### Backport to 2.2 by Mike Fletcher
 > from __future__ import generators
 > def ifilter( func, sequence, **named ):
 >       """Generator/iterator-based filter-function"""
 >       for item in sequence:
 >               if func(item, **named):
 >                       yield item
 > def ifilterfalse( func, sequence, **named ):
 >       """Generator/iterator-based negative filter-function"""
 >       for item in sequence:
 >               if not func(item, **named):
 >                       yield item
 > ### End backport
60c73
< from itertools import ifilter, ifilterfalse
---
 >

P:\backports\test>diff -b c:\bin\lang\py23\Lib\test\test_sets.py 
test_sets.py
2c2
<
---
 > from __future__ import generators
473c473
<     cases = "!="
---
 >     cases = ("!=",) # fix for Python 2.2
655c655
< False
---
 > 0
658c658
< True
---
 > 1
704c704
<     from test import test_sets
---
 >     import test_sets

_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/








More information about the Python-list mailing list