Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
contains
  • Loading branch information
youknowone committed Jan 1, 2026
commit 59cab4516f6681983dbd199e27d5e254069f6adb
32 changes: 14 additions & 18 deletions crates/vm/src/builtins/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,14 @@ fn reduce_set(
flags(BASETYPE, _MATCH_SELF)
)]
impl PySet {
#[pymethod]
fn __len__(&self) -> usize {
self.inner.len()
}

fn __contains__(&self, needle: &PyObject, vm: &VirtualMachine) -> PyResult<bool> {
self.inner.contains(needle, vm)
}

#[pymethod]
fn __sizeof__(&self) -> usize {
core::mem::size_of::<Self>() + self.inner.sizeof()
Expand All @@ -550,11 +553,6 @@ impl PySet {
}
}

#[pymethod]
fn __contains__(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult<bool> {
self.inner.contains(&needle, vm)
}

#[pymethod]
fn union(&self, others: PosArgs<ArgIterable>, vm: &VirtualMachine) -> PyResult<Self> {
self.fold_op(others.into_iter(), PySetInner::union, vm)
Expand Down Expand Up @@ -799,9 +797,9 @@ impl AsSequence for PySet {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PySet::sequence_downcast(seq).__len__())),
contains: atomic_func!(|seq, needle, vm| PySet::sequence_downcast(seq)
.inner
.contains(needle, vm)),
contains: atomic_func!(
|seq, needle, vm| PySet::sequence_downcast(seq).__contains__(needle, vm)
),
..PySequenceMethods::NOT_IMPLEMENTED
});
&AS_SEQUENCE
Expand Down Expand Up @@ -972,11 +970,14 @@ impl Constructor for PyFrozenSet {
)
)]
impl PyFrozenSet {
#[pymethod]
fn __len__(&self) -> usize {
self.inner.len()
}

fn __contains__(&self, needle: &PyObject, vm: &VirtualMachine) -> PyResult<bool> {
self.inner.contains(needle, vm)
}

#[pymethod]
fn __sizeof__(&self) -> usize {
core::mem::size_of::<Self>() + self.inner.sizeof()
Expand All @@ -995,11 +996,6 @@ impl PyFrozenSet {
}
}

#[pymethod]
fn __contains__(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult<bool> {
self.inner.contains(&needle, vm)
}

#[pymethod]
fn union(&self, others: PosArgs<ArgIterable>, vm: &VirtualMachine) -> PyResult<Self> {
self.fold_op(others.into_iter(), PySetInner::union, vm)
Expand Down Expand Up @@ -1142,9 +1138,9 @@ impl AsSequence for PyFrozenSet {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyFrozenSet::sequence_downcast(seq).__len__())),
contains: atomic_func!(|seq, needle, vm| PyFrozenSet::sequence_downcast(seq)
.inner
.contains(needle, vm)),
contains: atomic_func!(
|seq, needle, vm| PyFrozenSet::sequence_downcast(seq).__contains__(needle, vm)
),
..PySequenceMethods::NOT_IMPLEMENTED
});
&AS_SEQUENCE
Expand Down
5 changes: 0 additions & 5 deletions crates/vm/src/stdlib/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,6 @@ mod _collections {
self.borrow_deque().len()
}

#[pymethod]
fn __add__(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<Self> {
self.concat(&other, vm)
}

fn concat(&self, other: &PyObject, vm: &VirtualMachine) -> PyResult<Self> {
if let Some(o) = other.downcast_ref::<Self>() {
let mut deque = self.borrow_deque().clone();
Expand Down
1 change: 0 additions & 1 deletion crates/vm/src/stdlib/winreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ mod winreg {
zelf.Close(vm)
}

#[pymethod]
fn __int__(&self) -> usize {
self.hkey.load() as usize
}
Expand Down