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: Add detailed return value information for set.intersection function
Type: enhancement Stage: resolved
Components: Documentation Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, mark.dickinson, rhettinger, 양유석
Priority: normal Keywords:

Created on 2017-12-17 05:29 by 양유석, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg308484 - (view) Author: 양유석 (양유석) Date: 2017-12-17 05:29
I think it's intentional behavior seems to be minor though.

At a glance, I assume that a.set(b) should return items in a. But I found out the implementation always return items in smaller set.

There is no issue for common case, but custom class can make a trouble. So, I think additional information of return value is helpful.
msg308493 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2017-12-17 18:28
To clarify, are you referring to this behaviour?

>>> a = {1, 2, 3}
>>> b = {1.0, 4.0}
>>> a.intersection(b)  # expect {1}
{1.0}

I'd personally expect this to be implementation-dependent: since for set operations you usually only care about objects up to equality, it would be a bit unusual to care whether you get {1} or {1.0} in the above situation, and I'd say the implementation should be free to do whatever's convenient. Making documented guarantees would unnecessarily constrain other implementations.

I suppose one could document the *lack* of a guarantee here ...
msg308522 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-12-18 08:00
The implementation detail is not documented because it is not guaranteed.  The behavior has changed over time and other implementation are allowed to do something different.  For example, collections.abc.Set.__and__ has different behavior.
msg308540 - (view) Author: 양유석 (양유석) Date: 2017-12-18 10:21
Ok, I got a point of implementation-dependent things. Thank you for comments.
History
Date User Action Args
2022-04-11 14:58:55adminsetgithub: 76530
2017-12-18 10:21:12양유석setmessages: + msg308540
2017-12-18 08:00:14rhettingersetstatus: open -> closed
resolution: not a bug
messages: + msg308522

stage: resolved
2017-12-17 18:28:43mark.dickinsonsetnosy: + rhettinger, mark.dickinson
messages: + msg308493
2017-12-17 05:29:21양유석create