From 610a93ea2623ff324c99c52147d78838335ae900 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 11 Jun 2008 00:44:47 +0000 Subject: Handle the case with zero arguments. --- Lib/test/test_set.py | 6 ++++++ Objects/setobject.c | 3 +++ 2 files changed, 9 insertions(+) diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index 729cc3b..b32d953 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -104,6 +104,12 @@ class TestJointOps(unittest.TestCase): self.assertEqual(self.thetype('abcba').intersection(C('ccb')), set('bc')) self.assertEqual(self.thetype('abcba').intersection(C('ef')), set('')) self.assertEqual(self.thetype('abcba').intersection(C('cbcf'), C('bag')), set('b')) + s = self.thetype('abcba') + z = s.intersection() + if self.thetype == frozenset(): + self.assertEqual(id(s), id(z)) + else: + self.assertNotEqual(id(s), id(z)) def test_isdisjoint(self): def f(s1, s2): diff --git a/Objects/setobject.c b/Objects/setobject.c index a892dc8..1127680 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1312,6 +1312,9 @@ set_intersection_multi(PySetObject *so, PyObject *args) Py_ssize_t i; PyObject *result = (PyObject *)so; + if (PyTuple_GET_SIZE(args) == 0) + return set_copy(so); + Py_INCREF(so); for (i=0 ; i