set and frozenset unit tests?

Jacob Page apoco at
Fri Jul 15 05:58:04 CEST 2005

Steven Bethard wrote:
> Jacob Page wrote:
>> Oye, there's quite a number of set and frozenset features that aren't 
>> well-documented that I now need to implement.  What a fun chore!
> It would be a great help if you could submit appropriate documentation 
> patches for the areas you don't think are well-documented:

Hmm, after closer scrutiny, I'm not sure if the documentation really 
does need modification.  The largest incompatibility between IntervalSet 
and set was that my code wasn't enforcing hashability, and that property 
of sets actually IS documented.  However, there are two minor things I 
don't see documented that caught me by surprise:

* Since the <=, <, >, and >= operators raise an exception if the 
right-hand operand is not a set or frozenset,  it seemed reasonable to 
me to assume that == and != should, too.  However, the test suite for 
sets expect the comparisons to be allowed; == between a set and non-set 
return False, != returns True.  Seems inconsistent with the rest of the 
operators, but then again, the odd use of > and < for purposes other 
than ordering also seems strange.

* Apparently, if fs is a frozenset instance, fs.copy() returns a 
reference to fs instead of a copy of fs, and frozenset(fs) does the 
same.  The unit tests also ensure that subclasses of frozenset don't do 
this.  It makes sense that it's done that way to save on storage space, 
but it's not documented that this happens.

Both issues seem to be pretty minor unless you're making functionally 
equivalent classes.  I'm sure neither one will confuse someone into 
using them improperly, so I think it's fine to leave the docs alone.

By the way, IntervalSet and FrozenIntervalSet, when used in place of set 
and frozenset, now pass most of the tests.  One notable difference 
between them is that whereas sets can contain any hashable object, 
IntervalSet elements must be both hashable and orderable (implement 
__cmp__).  Thus, commands like IntervalSet([FrozenIntervalSet(...)]) 
fail, unlike set([frozenset(...)]).

I've also changed the methods with mixedCase capitalization to 
lower_case_with_underscores, as recommended by PEP 8.

Version 0.2.2 of the module can now be downloaded from  I'm about to freeze the 
interfaces and transition the module to beta, so if you have any 
interest in the project or design change ideas, please send feedback soon.

More information about the Python-list mailing list