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 rhettinger
Recipients rhettinger, stutzbach, ysj.ray
Date 2010-12-01.00:01:19
SpamBayes Score 2.0472346e-11
Marked as misclassified No
Message-id <1291161683.4.0.687317394097.issue8743@psf.upfronthosting.co.za>
In-reply-to
Content
Daniel, do you have time to work on this one?

If so, go ahead an make setobject.c accept any instance of collections.Set and make the corresponding change to the ABCs:

    def __or__(self, other):
        if not isinstance(other, Set):
            return NotImplemented
        chain = (e for s in (self, other) for e in s)
        return self._from_iterable(chain)

The code in the attached prelim.patch has working C code isinstance(x, collections.Set), but the rest of the patch that applies is has not been tested.  It needs to be applied very carefully and thoughtfully because:
* internally, the self and other can get swapped on a binary call
* we can't make *any* assumptions about "other" (that duplicates have actually been eliminated or the the elements are even hashable).

The most reliable thing to do for the case where PyAnySet(obj) is False but isinstance(obj, collections.Set) is true is to call the named method such as s.union(other) instead of continuing with s.__or__ which was designed only with real sets in mind.
History
Date User Action Args
2010-12-01 00:01:23rhettingersetrecipients: + rhettinger, stutzbach, ysj.ray
2010-12-01 00:01:23rhettingersetmessageid: <1291161683.4.0.687317394097.issue8743@psf.upfronthosting.co.za>
2010-12-01 00:01:19rhettingerlinkissue8743 messages
2010-12-01 00:01:19rhettingercreate