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 <rep...@bugs.python.org>
<http://bugs.python.org/issue17626>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to