8000 small fixes by youknowone · Pull Request #6444 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 5 additions & 4 deletions crates/vm/src/builtins/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,13 @@ impl PyMemoryView {
#[pymethod]
fn __len__(&self, vm: &VirtualMachine) -> PyResult<usize> {
self.try_not_released(vm)?;
Ok(if self.desc.ndim() == 0 {
1
if self.desc.ndim() == 0 {
// 0-dimensional memoryview has no length
Err(vm.new_type_error("0-dim memory has no length".to_owned()))
} else {
// shape for dim[0]
self.desc.dim_desc[0].0
})
Ok(self.desc.dim_desc[0].0)
}
}

#[pymethod]
Expand Down
22 changes: 8 additions & 14 deletions crates/vm/src/types/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,9 @@ where
pub trait Initializer: PyPayload {
type Args: FromArgs;

#[pyslot]
#[inline]
#[pyslot]
#[pymethod(name = "__init__")]
fn slot_init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
#[cfg(debug_assertions)]
let class_name_for_debug = zelf.class().name().to_string();
Expand Down Expand Up @@ -979,13 +980,6 @@ pub trait Initializer: PyPayload {
Self::init(zelf, args, vm)
}

#[pymethod]
#[inline]
fn __init__(zelf: PyRef<Self>, args: Self::Args, vm: &VirtualMachine) -> PyResult<()> {
// TODO: check if this is safe. zelf may need to be `PyObjectRef`
Self::init(zelf, args, vm)
}

fn init(zelf: PyRef<Self>, args: Self::Args, vm: &VirtualMachine) -> PyResult<()>;
}

Expand Down Expand Up @@ -1340,8 +1334,8 @@ pub trait GetAttr: PyPayload {

#[inline]
#[pymethod]
fn __getattribute__(zelf: PyRef<Self>, name: PyStrRef, vm: &VirtualMachine) -> PyResult {
Self::getattro(&zelf, &name, vm)
fn __getattribute__(zelf: PyObjectRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult {
Self::slot_getattro(&zelf, &name, vm)
}
}

Expand Down Expand Up @@ -1371,18 +1365,18 @@ pub trait SetAttr: PyPayload {
#[inline]
#[pymethod]
fn __setattr__(
zelf: PyRef<Self>,
zelf: PyObjectRef,
name: PyStrRef,
value: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<()> {
Self::setattro(&zelf, &name, PySetterValue::Assign(value), vm)
Self::slot_setattro(&zelf, &name, PySetterValue::Assign(value), vm)
}

#[inline]
#[pymethod]
fn __delattr__(zelf: PyRef<Self>, name: PyStrRef, vm: &VirtualMachine) -> PyResult<()> {
Self::setattro(&zelf, &name, PySetterValue::Delete, vm)
fn __delattr__(zelf: PyObjectRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult<()> {
Self::slot_setattro(&zelf, &name, PySetterValue::Delete, vm)
}
}

Expand Down
Loading
0