This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 'set' union() fails in specific use case
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, fschaef2, rhettinger
Priority: normal Keywords:

Created on 2010-03-16 06:17 by fschaef2, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg101154 - (view) Author: Frank Rene Schaefer (fschaef2) Date: 2010-03-16 06:17
The union operation fails in the following use case

Python 2.6.4 (r264:75706, Jan 30 2010, 22:50:05) 
[GCC 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036]] on linux2
>>> def func():
...     a = set([0])
...     a.pop()
...     b = set([1, 2])
...     a.union(b)
...     return a
... 
>>> func()
set([])

Note, that is does *not* fail if it is *not* inside a function, i.e.

>>> a = set([0])
>>> a.pop()
0
>>> b = set([1, 2])
>>> a.union(b)
set([1, 2])
>>>
msg101157 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-03-16 07:42
set.union doesn't change the first set (i.e. a), but returns a new sets (i.e. c):
>>> def func():
...   a = set([0])
...   a.pop()
...   print 'a:', a
...   b = set([1, 2])
...   c = a.union(b)
...   print 'a:', a
...   return c
...
>>> func()
a: set([])
a: set([])
set([1, 2])
msg101207 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-03-17 00:20
Frank, try using "update" instead of "union".
msg101213 - (view) Author: Frank Rene Schaefer (fschaef2) Date: 2010-03-17 08:46
Thanks, for the comments. I got it. 

In German we would say 'I was standing on the water hose' ... 
That is, something was choking the flow of my thoughts.

Best Regards

Frank
History
Date User Action Args
2022-04-11 14:56:58adminsetgithub: 52400
2010-03-17 08:46:58fschaef2setmessages: + msg101213
2010-03-17 00:20:24rhettingersetnosy: + rhettinger
messages: + msg101207
2010-03-16 07:42:25ezio.melottisetstatus: open -> closed

nosy: + ezio.melotti
messages: + msg101157

resolution: not a bug
stage: resolved
2010-03-16 06:17:29fschaef2create