[New-bugs-announce] [issue17626] set's __isub__ doesn't support non-sets.

Roy Wellington report at bugs.python.org
Wed Apr 3 19:34:58 CEST 2013

New submission from Roy Wellington:

The following:

s = set(range(10))

s -= (1, 2, 3)

raises a TypeError. Yet the following, which is more verbose and equivalent, succeeds:

s.difference_update((1, 2, 3))

Under the hood, __isub__ calls difference_update to do its work. Unfortunately, __isub__ explicitly checks that the parameter is a set, even though difference_update can handle more than just sets. Could set.__isub__ just pass along the tuple to difference update, allowing __isub__ to operate on any iterable?

For the purposes of "remove these elements from this set", any iterable works just as well as any other. It should O(number of elements to remove) in time (for sets, tuples, lists, etc.) and constant in memory, aside from the memory required for the parameters themselves.

messages: 185941
nosy: Roy.Wellington
priority: normal
severity: normal
status: open
title: set's __isub__ doesn't support non-sets.
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list