GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `&=` and `-=` operator between Set types do not work correctly. · Issue #3992 · RustPython/RustPython

&= and -= operator between Set types do not work correctly. #3992

New issue
Copy link
New issue
Copy link
Closed
#5860
Closed
&= and -= operator between Set types do not work correctly.#3992
#5860
Copy link
Labels
z-ca-2022Tag to track contrubution-academy 2022Tag to track contrubution-academy 2022

Description

@tgsong827
tgsong827
opened on Aug 2, 2022
Issue body actions

Feature

I'm trying to fix @unittest.expectedFailure test_inplace_on_self in file test_set.py.

def test_inplace_on_self(self):
    t = self.s.copy()
    t |= t
    self.assertEqual(t, self.s)
    t &= t
    self.assertEqual(t, self.s).      -> FAIL
    t -= t
    self.assertEqual(t, self.thetype()).     -> FAIL
    t = self.s.copy()
    t ^= t
    self.assertEqual(t, self.thetype())

I found the two operator fail.
&= and -= is not work correctly.

[ &= ]

  • RustPython
>>>>> s = set({'a', 'b', 'c'})
>>>>> s &= s
>>>>> s
set()
  • CPython
>>> s = set({'a', 'b', 'c'})
>>> s &= s
>>> s
{'b', 'c', 'a'}

[ -= ]

  • RustPython
>>>>> s = set({'a', 'b', 'c'})
>>>>> s -= s
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: set changed size during iteration

Maybe the points to start

  • &=
#[pymethod(magic)]
fn iand(zelf: PyRef<Self>, set: AnySet, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
    zelf.inner
        .intersection_update(std::iter::once(set.into_iterable(vm)?), vm)?;
    Ok(zelf)
}
  • -=
#[pymethod(magic)]
fn isub(zelf: PyRef<Self>, set: AnySet, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
    zelf.inner
        .difference_update(set.into_iterable_iter(vm)?, vm)?;
    Ok(zelf)
}

Python Documentation

CPython Method

  • &=
    https://github.com/python/cpython/blob/75a6441718dcbc65d993c9544e67e25bef120e82/Objects/setobject.c#L1181-L1261

  • -=
    https://github.com/python/cpython/blob/75a6441718dcbc65d993c9544e67e25bef120e82/Objects/setobject.c#L1406-L1461

Activity

  1. tgsong827 commented on Aug 2, 2022

    @tgsong827
    tgsong827
    on Aug 2, 2022
    ContributorAuthor
    More actions

    This may be related with #3881 #3912.
    Can I try it after #3912 is merged?

  2. youknowone
    added
    z-ca-2022Tag to track contrubution-academy 2022Tag to track contrubution-academy 2022
    on Aug 2, 2022
  3. arihant2math commented on Apr 22, 2025

    @arihant2math
    arihant2math
    on Apr 22, 2025
    Contributor
    More actions

    &= now works, -= still fails

  4. youknowone
    closed this as completedin #5860on Jun 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    z-ca-2022Tag to track contrubution-academy 2022Tag to track contrubution-academy 2022

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.