Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Open
@tgsong827

Description

@tgsong827
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

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.