Skip to content

Commit 272b36d

Browse files
authored
small fixes (#6444)
* fix memoryview * retype slot zelf
1 parent 30cc772 commit 272b36d

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

crates/vm/src/builtins/memory.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,13 @@ impl PyMemoryView {
693693
#[pymethod]
694694
fn __len__(&self, vm: &VirtualMachine) -> PyResult<usize> {
695695
self.try_not_released(vm)?;
696-
Ok(if self.desc.ndim() == 0 {
697-
1
696+
if self.desc.ndim() == 0 {
697+
// 0-dimensional memoryview has no length
698+
Err(vm.new_type_error("0-dim memory has no length".to_owned()))
698699
} else {
699700
// shape for dim[0]
700-
self.desc.dim_desc[0].0
701-
})
701+
Ok(self.desc.dim_desc[0].0)
702+
}
702703
}
703704

704705
#[pymethod]

crates/vm/src/types/slot.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,9 @@ where
950950
pub trait Initializer: PyPayload {
951951
type Args: FromArgs;
952952

953-
#[pyslot]
954953
#[inline]
954+
#[pyslot]
955+
#[pymethod(name = "__init__")]
955956
fn slot_init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
956957
#[cfg(debug_assertions)]
957958
let class_name_for_debug = zelf.class().name().to_string();
@@ -979,13 +980,6 @@ pub trait Initializer: PyPayload {
979980
Self::init(zelf, args, vm)
980981
}
981982

982-
#[pymethod]
983-
#[inline]
984-
fn __init__(zelf: PyRef<Self>, args: Self::Args, vm: &VirtualMachine) -> PyResult<()> {
985-
// TODO: check if this is safe. zelf may need to be `PyObjectRef`
986-
Self::init(zelf, args, vm)
987-
}
988-
989983
fn init(zelf: PyRef<Self>, args: Self::Args, vm: &VirtualMachine) -> PyResult<()>;
990984
}
991985

@@ -1340,8 +1334,8 @@ pub trait GetAttr: PyPayload {
13401334

13411335
#[inline]
13421336
#[pymethod]
1343-
fn __getattribute__(zelf: PyRef<Self>, name: PyStrRef, vm: &VirtualMachine) -> PyResult {
1344-
Self::getattro(&zelf, &name, vm)
1337+
fn __getattribute__(zelf: PyObjectRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult {
1338+
Self::slot_getattro(&zelf, &name, vm)
13451339
}
13461340
}
13471341

@@ -1371,18 +1365,18 @@ pub trait SetAttr: PyPayload {
13711365
#[inline]
13721366
#[pymethod]
13731367
fn __setattr__(
1374-
zelf: PyRef<Self>,
1368+
zelf: PyObjectRef,
13751369
name: PyStrRef,
13761370
value: PyObjectRef,
13771371
vm: &VirtualMachine,
13781372
) -> PyResult<()> {
1379-
Self::setattro(&zelf, &name, PySetterValue::Assign(value), vm)
1373+
Self::slot_setattro(&zelf, &name, PySetterValue::Assign(value), vm)
13801374
}
13811375

13821376
#[inline]
13831377
#[pymethod]
1384-
fn __delattr__(zelf: PyRef<Self>, name: PyStrRef, vm: &VirtualMachine) -> PyResult<()> {
1385-
Self::setattro(&zelf, &name, PySetterValue::Delete, vm)
1378+
fn __delattr__(zelf: PyObjectRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult<()> {
1379+
Self::slot_setattro(&zelf, &name, PySetterValue::Delete, vm)
13861380
}
13871381
}
13881382

0 commit comments

Comments
 (0)