Bug in Python set
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sun May 2 09:12:10 EDT 2010
On Sun, 02 May 2010 05:11:40 -0700, dmitrey wrote:
> Python 2.6.5 r265:79063
>>>>set().update(set()) is None
> True
> while I expect result of update to be set.
Change your expectations. Generally, methods which modify the object
rather than creating a new one return None.
>>> s = set([1,2,3])
>>> s.update(set([3, 4, 5]))
>>> s
{1, 2, 3, 4, 5}
> Also, result of set().add(None) is None while I expect it to be set
> with element None (or, maybe, it should be empty set?)
>>> s = set()
>>> s.add(None)
>>> s
{None}
Python sets have been used by tens of thousands of programmers for many
years now. Which do you think is more likely?
(1) Not one person before you noticed that something as fundamental as
adding an item to a set is buggy;
or
(2) You have misunderstood what is happening?
--
Steven
More information about the Python-list
mailing list