Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 63853bb

Browse files
committed
Issue 6573: Fix set.union() for cases where self is in the argument chain.
1 parent 7bc66b1 commit 63853bb

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/test/test_set.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ def test_union(self):
8282
self.assertEqual(self.thetype('abcba').union(C('ef')), set('abcef'))
8383
self.assertEqual(self.thetype('abcba').union(C('ef'), C('fg')), set('abcefg'))
8484

85+
# Issue #6573
86+
x = self.thetype()
87+
self.assertEqual(x.union(set([1]), x, set([2])), self.thetype([1, 2]))
88+
8589
def test_or(self):
8690
i = self.s.union(self.otherword)
8791
self.assertEqual(self.s | set(self.otherword), i)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Core and Builtins
1414

1515
- Issue #6540: Fixed crash for bytearray.translate() with invalid parameters.
1616

17+
- Issue #6573: set.union() stopped processing inputs if an instance of self
18+
occurred in the argument chain.
19+
1720
- Issue #6070: On posix platforms import no longer copies the execute bit
1821
from the .py file to the .pyc file if it is set.
1922

Objects/setobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ set_union(PySetObject *so, PyObject *args)
11871187
for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
11881188
other = PyTuple_GET_ITEM(args, i);
11891189
if ((PyObject *)so == other)
1190-
return (PyObject *)result;
1190+
continue;
11911191
if (set_update_internal(result, other) == -1) {
11921192
Py_DECREF(result);
11931193
return NULL;

0 commit comments

Comments
 (0)