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-09-02.00:07:26
SpamBayes Score 3.846412e-08
Marked as misclassified No
Message-id <1283386052.99.0.523936343968.issue8743@psf.upfronthosting.co.za>
In-reply-to
Content
The operator methods in setobject.c should be liberalized to accept instances of collections.Set as arguments.  For speed, they should continue to check PyAnySet_Check(other) first and then if that fails, fall back to testing PyObject_IsInstance(other, collections.Set).  

Internally, the set methods will still need to process "other" as just an iterable container because it cannot rely on elements in "other" as being hashable (for example, the ListBasedSet in the docs does not require hashability) or unique (as perceived by setobject.c it may not work with some set implementing a key-function for an equivalence class whose key-function would be unknown to setobject.c which relies on __hash__ and __eq__).

To implement PyObject_IsInstance(other, collections.Set), there may be a bootstrap issue (with the C code being compiled and runnable before _abcoll.py is able to create the Set ABC).  If so, it may be necessary to create an internal _BaseSet object in setobject.c that can be used in collections.Set.  Alternatively, the code in setobject.c can lazily (at runtime) lookup collections.Set by name and cache it so that we only do one successful lookup per session.

Whatever approach is taken, it should be done with an eye towards the larger problem that Python is filled with concrete isinstance() checks that pre-date ABCs and many of those need to be liberalized (accepting a registered ABC and providing different execution paths for known and unknown concrete types).
History
Date User Action Args
2010-09-02 00:07:33rhettingersetrecipients: + rhettinger, stutzbach, ysj.ray
2010-09-02 00:07:32rhettingersetmessageid: <1283386052.99.0.523936343968.issue8743@psf.upfronthosting.co.za>
2010-09-02 00:07:28rhettingerlinkissue8743 messages
2010-09-02 00:07:26rhettingercreate