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
Next Next commit
fix sequence_repeat wrappers
  • Loading branch information
youknowone committed Jan 1, 2026
commit 844cb03c0330bd922d4d8b99db1529d2429ed30c
6 changes: 3 additions & 3 deletions crates/vm/src/builtins/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
class::PyClassImpl,
common::hash::PyHash,
convert::{ToPyObject, ToPyResult},
function::{FuncArgs, PyMethodDef, PyMethodFlags, PySetterValue},
function::{ArgSize, FuncArgs, PyMethodDef, PyMethodFlags, PySetterValue},
protocol::{PyNumberBinaryFunc, PyNumberTernaryFunc, PyNumberUnaryFunc},
types::{
Callable, Comparable, DelFunc, DescrGetFunc, DescrSetFunc, GenericMethod, GetDescriptor,
Expand Down Expand Up @@ -593,8 +593,8 @@ impl SlotFunc {
func(obj.sequence_unchecked(), &other, vm)
}
SlotFunc::SeqRepeat(func) => {
let (n,): (isize,) = args.bind(vm)?;
func(obj.sequence_unchecked(), n, vm)
let (n,): (ArgSize,) = args.bind(vm)?;
func(obj.sequence_unchecked(), n.into(), vm)
}
SlotFunc::SeqItem(func) => {
let (index,): (isize,) = args.bind(vm)?;
Expand Down
26 changes: 20 additions & 6 deletions crates/vm/src/types/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,16 @@ fn sequence_contains_wrapper(
contains_wrapper(seq.obj, needle, vm)
}

#[inline(never)]
fn sequence_repeat_wrapper(seq: PySequence<'_>, n: isize, vm: &VirtualMachine) -> PyResult {
vm.call_special_method(seq.obj, identifier!(vm, __mul__), (n,))
}

#[inline(never)]
fn sequence_inplace_repeat_wrapper(seq: PySequence<'_>, n: isize, vm: &VirtualMachine) -> PyResult {
vm.call_special_method(seq.obj, identifier!(vm, __imul__), (n,))
}

fn repr_wrapper(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyRef<PyStr>> {
let ret = vm.call_special_method(zelf, identifier!(vm, __repr__), ())?;
ret.downcast::<PyStr>().map_err(|obj| {
Expand Down Expand Up @@ -1294,12 +1304,16 @@ impl PyType {
accessor.inherit_from_mro(self);
}
}
SlotAccessor::SqRepeat | SlotAccessor::SqInplaceRepeat => {
// Sequence repeat uses sq_repeat slot - no generic wrapper needed
// (handled by number protocol fallback)
if !ADD {
accessor.inherit_from_mro(self);
}
SlotAccessor::SqRepeat => {
update_sub_slot!(as_sequence, repeat, sequence_repeat_wrapper, SeqRepeat)
}
SlotAccessor::SqInplaceRepeat => {
update_sub_slot!(
as_sequence,
inplace_repeat,
sequence_inplace_repeat_wrapper,
SeqRepeat
)
}
SlotAccessor::SqItem => {
update_sub_slot!(as_sequence, item, sequence_getitem_wrapper, SeqItem)
Expand Down