[docs] [issue20902] Which operand is preferred by set operations? Missing information in the documentation

Terry J. Reedy report at bugs.python.org
Sat Mar 15 00:56:39 CET 2014


Terry J. Reedy added the comment:

Defining equality to ignore the .value attribute (and the id), says that they *do not matter*. Python believes you and the interpreter does what it does. If we had made a 'first or second operand wins' claim, we would not have been able to optimize intersection by starting with the smaller set. I may mis-remember but I believe we changed after someone noticed that something like {1] & set(range(10000)) versus set(range(10000)) & {1} had very different run times.

I agree with Raymond that the docs for intersection and union should be left as is.

I could read the doc for A.intersection_update(B) as saying that it keeps all items in A that also appear in B, with appear defined on the basis of ==, so that the result is a subset of the actual items in A. If that is the intent, it could be made clearer.

The doc A.update(B) (union) come close to saying that all items in A remain and items in B not in A get added, so that the result all the items in A. Again, if that is the intent, it could be made explicit, and people who want to determine which operand wins could use the update functions to do so.

----------
nosy: +terry.reedy

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20902>
_______________________________________


More information about the docs mailing list