classification
Title: Small _abcoll Bugs / Oddities
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: duplicate
Dependencies: Superseder: set() operators don't work with collections.Set instances
View: 8743
Assigned To: rhettinger Nosy List: Ramchandra Apte, aronacher, barry, benjamin.peterson, flox, georg.brandl, mark.dickinson, mdengler, ncoghlan, rhettinger, stutzbach, yselivanov
Priority: critical Keywords:

Created on 2008-03-03 21:22 by aronacher, last changed 2014-02-02 08:06 by ncoghlan. This issue is now closed.

Messages (18)
msg63232 - (view) Author: Armin Ronacher (aronacher) * (Python committer) Date: 2008-03-03 21:24
_abcoll.py references intertools.chain but doesn't import it.  This
breaks Set subclasses.  Additionally the abstract base classes don't
provide the right hand operator callbacks or how you want to call them.
 So __add__ is there but __radd__ not which for example leads to the
problem that "foo() + set()" works but "set() + foo" not.

And the third oddity in that module is that Callable defines an abstract
method for __contains__ which makes no sense but none for __call__.
msg63233 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-03-03 21:26
I fixed the import in r61211.

Raymond, can you sort out the set operations?
msg63240 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2008-03-03 22:22
* Removed the dependency on itertools:  r61213.

* Fixed nasty cut-and-paste error in Callable:  r61214

Leaving the other one for Guido.  I suspect the __radd__ style methods
are can of worms best left unopened for now.  The right solution
probably involves visiting every piece of code in Python that makes a
concrete isinstance/issubclass test and replacing it with an abstract
test.  That may have unexpected side-effects, may be hard to test, and
may kill performance.
msg63861 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-03-18 03:04
I'm setting this to critical to ensure that I will at least have a
thorough look at this before the release.  I'm not sure whether I will
decide to address it or leave it alone.
msg70460 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-31 01:56
Ping.
msg72454 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2008-09-04 01:52
There's been no activity on this, but I don't believe it's serious
enough to block the release.
msg72469 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2008-09-04 02:49
Recommend dealing with this in 3.1.
The __radd__ issue is non-trivial
and can't easily be dealt with at this point.
msg72471 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2008-09-04 02:50
Thanks Raymond.  Lowering the priority to critical and pushing this back
to 3.1.
msg79229 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2009-01-06 05:03
I'm not going to get to this.
msg114450 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-08-20 20:32
3.1 is long gone.  Should this be addressed for 3.2?
msg123924 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-12-14 03:49
Yes, if you have a chance to think it through, it would be nice to get this fixed-up.
msg123995 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-12-15 00:55
Minor point of clarity: you mean __rand__ not __radd__, right?  Set objects do not support addition at all.

Adding the __rand__ methods to collections.Set in and of itself is straightforward:

    def __rsub__(self, other):
        return self._from_iterable(other) - self
    __ror__ = __or__
    __rand__ = __and__
    __rxor__ = __xor__

I'm not sure I understand the can of worms.  While replacing concrete tests with abstract tests may be worthwhile goal in its own right, why is it necessary to solve the particular shortcoming of missing __r* methods?

Probably I'm missing something.  With just the minimal change above, what kinds of things do you expect to fail?

(assuming Issue8743 is also fixed)
msg124239 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-12-17 17:57
Raymond,

Do you have around 10 minutes today to look at the patch I submitted in Issue 8743?  It appears to solve both this issue and that one, which have priorities critical and high, respectively.

It's a reasonably small patch: around 20 lines changed plus 20 lines added, all Python code.  Here's a direct link:

http://bugs.python.org/file20045/set-with-Set.patch

If it looks good to you, I'd like to commit it in time for 3.2b2 so that it gets as much exercise as possible before 3.2-final.

Earlier you had expressed that adding the __rand__ methods to collections.Set would be tricky issue, so I'm concerned that I have overlooked something important and obvious.

(Feedback from others is, of course, welcome as well)
msg179871 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2013-01-13 13:16
Bump.
msg189752 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-05-21 13:34
Armin pointed out in http://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/ that one nasty consequence of the remaining part of this bug and issue 8743 is making it much harder than it should be to use the ItemsView, KeysView and ValuesView from collections.abc to implement third party mappings that behave like the builtin dict.
msg207285 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2014-01-04 14:03
Raymond, will you have a chance to look at this before 3.4rc1? Otherwise I'd like to take it.
msg207676 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-01-08 06:43
Yes, I'll have a look shortly.
msg209958 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2014-02-02 08:06
With the only remaining issue here being the misbehaviour of the Set and MutableSet ABCs when dealing with other types (the other issues in Armin's original report were much simpler and fixed promptly), I'm closing this as a duplicate of issue 8743 (where I just uploaded an up to date patch based on the patch Daniel linked to above)
History
Date User Action Args
2014-02-02 08:06:49ncoghlansetstatus: open -> closed
superseder: set() operators don't work with collections.Set instances
resolution: duplicate
messages: + msg209958
2014-01-31 22:58:15yselivanovsetnosy: + yselivanov
2014-01-11 16:12:57mark.dickinsonsetnosy: + mark.dickinson
2014-01-08 06:43:39rhettingersetmessages: + msg207676
2014-01-04 14:03:35ncoghlansetmessages: + msg207285
2013-11-27 09:08:42mdenglersetnosy: + mdengler
2013-05-21 13:34:56ncoghlansetmessages: + msg189752
2013-05-20 15:10:04floxsetnosy: + flox
2013-05-20 14:29:21ncoghlansetnosy: + ncoghlan
2013-01-16 22:59:24stutzbachsetassignee: stutzbach -> rhettinger
2013-01-13 13:16:11Ramchandra Aptesetnosy: + Ramchandra Apte
messages: + msg179871
2010-12-17 17:57:19stutzbachsetnosy: barry, georg.brandl, rhettinger, benjamin.peterson, stutzbach, aronacher
messages: + msg124239
2010-12-15 00:55:02stutzbachsetmessages: + msg123995
2010-12-14 03:49:48rhettingersetassignee: stutzbach
messages: + msg123924
versions: - Python 3.1
2010-12-14 01:14:03r.david.murraysettype: behavior
stage: test needed
2010-08-20 20:32:23stutzbachsetmessages: + msg114450
2010-05-17 21:23:37pitrousetnosy: + stutzbach

versions: + Python 3.2
2009-01-06 05:03:49gvanrossumsetnosy: - gvanrossum
2009-01-06 05:03:39gvanrossumsetassignee: gvanrossum -> (no value)
messages: + msg79229
2008-09-04 02:50:55barrysetpriority: deferred blocker -> critical
messages: + msg72471
versions: + Python 3.1, - Python 2.6, Python 3.0
2008-09-04 02:49:28rhettingersetmessages: + msg72469
2008-09-04 01:52:11barrysetpriority: release blocker -> deferred blocker
nosy: + barry
messages: + msg72454
2008-08-21 14:57:30benjamin.petersonsetpriority: critical -> release blocker
2008-07-31 01:56:34benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg70460
2008-03-18 03:04:52gvanrossumsetpriority: critical
messages: + msg63861
2008-03-04 06:52:25rhettingersetmessages: - msg63238
2008-03-03 22:22:04rhettingersetassignee: rhettinger -> gvanrossum
versions: + Python 2.6
messages: + msg63240
nosy: + gvanrossum
2008-03-03 21:55:26rhettingersetmessages: + msg63238
2008-03-03 21:26:31georg.brandlsetassignee: rhettinger
messages: + msg63233
nosy: + rhettinger, georg.brandl
2008-03-03 21:24:59aronachersetmessages: + msg63232
2008-03-03 21:22:10aronachercreate