Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small _abcoll Bugs / Oddities #46479

Closed
mitsuhiko opened this issue Mar 3, 2008 · 18 comments
Closed

Small _abcoll Bugs / Oddities #46479

mitsuhiko opened this issue Mar 3, 2008 · 18 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@mitsuhiko
Copy link
Member

BPO 2226
Nosy @warsaw, @birkenfeld, @rhettinger, @mdickinson, @ncoghlan, @benjaminp, @mitsuhiko, @florentx, @1st1
Superseder
  • bpo-8743: set() operators don't work with collections.Set instances
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2014-02-02.08:06:49.965>
    created_at = <Date 2008-03-03.21:22:10.756>
    labels = ['type-bug', 'library']
    title = 'Small _abcoll Bugs / Oddities'
    updated_at = <Date 2014-02-02.08:06:49.963>
    user = 'https://github.com/mitsuhiko'

    bugs.python.org fields:

    activity = <Date 2014-02-02.08:06:49.963>
    actor = 'ncoghlan'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2014-02-02.08:06:49.965>
    closer = 'ncoghlan'
    components = ['Library (Lib)']
    creation = <Date 2008-03-03.21:22:10.756>
    creator = 'aronacher'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 2226
    keywords = []
    message_count = 18.0
    messages = ['63232', '63233', '63240', '63861', '70460', '72454', '72469', '72471', '79229', '114450', '123924', '123995', '124239', '179871', '189752', '207285', '207676', '209958']
    nosy_count = 12.0
    nosy_names = ['barry', 'georg.brandl', 'rhettinger', 'mark.dickinson', 'ncoghlan', 'benjamin.peterson', 'stutzbach', 'aronacher', 'flox', 'Ramchandra Apte', 'mdengler', 'yselivanov']
    pr_nums = []
    priority = 'critical'
    resolution = 'duplicate'
    stage = 'test needed'
    status = 'closed'
    superseder = '8743'
    type = 'behavior'
    url = 'https://bugs.python.org/issue2226'
    versions = ['Python 3.2']

    @mitsuhiko mitsuhiko added the stdlib Python modules in the Lib dir label Mar 3, 2008
    @mitsuhiko
    Copy link
    Member Author

    _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__.

    @birkenfeld
    Copy link
    Member

    I fixed the import in r61211.

    Raymond, can you sort out the set operations?

    @rhettinger
    Copy link
    Contributor

    • 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.

    @rhettinger rhettinger assigned gvanrossum and unassigned rhettinger Mar 3, 2008
    @gvanrossum
    Copy link
    Member

    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.

    @benjaminp
    Copy link
    Contributor

    Ping.

    @warsaw
    Copy link
    Member

    warsaw commented Sep 4, 2008

    There's been no activity on this, but I don't believe it's serious
    enough to block the release.

    @rhettinger
    Copy link
    Contributor

    Recommend dealing with this in 3.1.
    The __radd__ issue is non-trivial
    and can't easily be dealt with at this point.

    @warsaw
    Copy link
    Member

    warsaw commented Sep 4, 2008

    Thanks Raymond. Lowering the priority to critical and pushing this back
    to 3.1.

    @gvanrossum
    Copy link
    Member

    I'm not going to get to this.

    @gvanrossum gvanrossum removed their assignment Jan 6, 2009
    @stutzbach
    Copy link
    Mannequin

    stutzbach mannequin commented Aug 20, 2010

    3.1 is long gone. Should this be addressed for 3.2?

    @bitdancer bitdancer added the type-bug An unexpected behavior, bug, or error label Dec 14, 2010
    @rhettinger
    Copy link
    Contributor

    Yes, if you have a chance to think it through, it would be nice to get this fixed-up.

    @stutzbach
    Copy link
    Mannequin

    stutzbach mannequin commented Dec 15, 2010

    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 bpo-8743 is also fixed)

    @stutzbach
    Copy link
    Mannequin

    stutzbach mannequin commented Dec 17, 2010

    Raymond,

    Do you have around 10 minutes today to look at the patch I submitted in bpo-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)

    @RamchandraApte
    Copy link
    Mannequin

    RamchandraApte mannequin commented Jan 13, 2013

    Bump.

    @stutzbach stutzbach mannequin assigned rhettinger and unassigned stutzbach Jan 16, 2013
    @ncoghlan
    Copy link
    Contributor

    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 bpo-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.

    @ncoghlan
    Copy link
    Contributor

    ncoghlan commented Jan 4, 2014

    Raymond, will you have a chance to look at this before 3.4rc1? Otherwise I'd like to take it.

    @rhettinger
    Copy link
    Contributor

    Yes, I'll have a look shortly.

    @ncoghlan
    Copy link
    Contributor

    ncoghlan commented Feb 2, 2014

    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 bpo-8743 (where I just uploaded an up to date patch based on the patch Daniel linked to above)

    @ncoghlan ncoghlan closed this as completed Feb 2, 2014
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    8 participants