Issue 32349: Add detailed return value information for set.intersection function (original) (raw)

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:55 admin set github: 76530
2017-12-18 10:21:12 양유석 set messages: +
2017-12-18 08:00:14 rhettinger set status: open -> closedresolution: not a bugmessages: + stage: resolved
2017-12-17 18:28:43 mark.dickinson set nosy: + rhettinger, mark.dickinsonmessages: +
2017-12-17 05:29:21 양유석 create