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.

Author nyoshimizu
Recipients nyoshimizu
Date 2016-11-29.19:53:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1480449187.13.0.345778529202.issue28834@psf.upfronthosting.co.za>
In-reply-to
Content
The non-operator versions of set comparisons (intersection(), union(), etc.) exhibit
inconsistent type checking. They only check the first input before deciding whether or not to raise a TypeError exception. 

Therefore, it's possible to pass a set first, then other objects (e.g. lists, dicts, tuples) and a correct 'intersection' is returned (apparently by ignoring ordering and using the keys in dicts). I've attached demonstrative example for Python 3.5, although Python 2.7 appears to exhibit the same behavior.

I'm not sure what the intended behavior was (whether or not to require sets). 8.7.1 Set Objects states: "Note, the non-operator versions of union(), intersection(), difference(), and symmetric_difference() will accept any iterable as an argument."

Note that #8743 and #17626 appear to confirm that the operator versions should not accept non-sets and matches the observed behavior. As the latter issue points out, it's documented -- again in 8.7.1 -- that "...their operator based counterparts require their arguments to be sets." 

Is this behavior necessary but just not documented? The documentation states that "This precludes error-prone constructions like Set('abc') & 'cbs' in favor of the more readable Set('abc').intersection('cbs')." In the second example, a first set is needed to do the intersection, then 'cbs' gets typecast into a set (although I guess so was 'abc'). Then should the first inputs also be typecast as sets?
History
Date User Action Args
2016-11-29 19:53:07nyoshimizusetrecipients: + nyoshimizu
2016-11-29 19:53:07nyoshimizusetmessageid: <1480449187.13.0.345778529202.issue28834@psf.upfronthosting.co.za>
2016-11-29 19:53:07nyoshimizulinkissue28834 messages
2016-11-29 19:53:07nyoshimizucreate