Commit 8514e263 authored by Tim Peters's avatar Tim Peters

The set operation difference(X, None) was returning None instead of

returning X, contradicting the docs and common sense.
difference(None, X) continues to return None.
parent e166d581
......@@ -249,8 +249,11 @@ class IMerge(Interface):
"""Return the keys or items in c1 for which there is no key in
c2.
If c1 is None, then None is returned. If c2 is none, then c1
If c1 is None, then None is returned. If c2 is None, then c1
is returned.
If neither c1 nor c2 is None, the output is a Set if c1 is a Set or
TreeSet, and is a Bucket if c1 is a Bucket or BTree.
"""
def union(c1, c2):
......
......@@ -16,7 +16,7 @@
Set operations
****************************************************************************/
#define SETOPTEMPLATE_C "$Id: SetOpTemplate.c,v 1.24 2002/06/08 04:41:44 tim_one Exp $\n"
#define SETOPTEMPLATE_C "$Id: SetOpTemplate.c,v 1.25 2002/06/23 19:36:12 tim_one Exp $\n"
#ifdef INTSET_H
static int
......@@ -346,8 +346,9 @@ difference_m(PyObject *ignored, PyObject *args)
if (o1==Py_None || o2==Py_None)
{
Py_INCREF(Py_None);
return Py_None;
/* difference(None, X) -> None; difference(X, None) -> X */
Py_INCREF(o1);
return o1;
}
return set_operation(o1, o2, 1, -1, 1, 0, 0);
......
......@@ -68,22 +68,16 @@ class SetResult(TestCase):
C = op(None, None)
self.assert_(C is None)
for op in self.union, self.intersection:
for op in self.union, self.intersection, self.difference:
for A in self.As:
C = op(A, None)
self.assert_(C is A)
C = op(None, A)
self.assert_(C is A)
# XXX These difference results contradict the docs. The implementation
# XXX is almost certainly wrong, but can we change it?
for A in self.As:
C = self.difference(A, None)
self.assert_(C is None)
C = self.difference(None, A)
if op is self.difference:
self.assert_(C is None)
else:
self.assert_(C is A)
def testEmptyUnion(self):
for A in self.As:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment