Skip to content
Draft
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
23 changes: 12 additions & 11 deletions vm/src/builtins/getset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,19 @@ impl GetDescriptor for PyGetSet {
_cls: Option<PyObjectRef>,
vm: &VirtualMachine,
) -> PyResult {
let (zelf, obj) = match Self::_check(&zelf, obj, vm) {
Some(obj) => obj,
None => return Ok(zelf),
};
if let Some(ref f) = zelf.getter {
f(vm, obj)
if let Some(obj) = obj {
let (zelf, obj) = Self::_check(&zelf, obj, vm)?;
if let Some(ref f) = zelf.getter {
f(vm, obj)
} else {
Err(vm.new_attribute_error(format!(
"attribute '{}' of '{}' objects is not readable",
zelf.name,
Self::class(&vm.ctx).name()
)))
}
} else {
Err(vm.new_attribute_error(format!(
"attribute '{}' of '{}' objects is not readable",
zelf.name,
Self::class(&vm.ctx).name()
)))
Ok(zelf)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions vm/src/protocol/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,8 @@ impl PyObject {

// type protocol
// PyObject *PyObject_Type(PyObject *o)
pub fn obj_type(&self) -> PyObjectRef {
self.class().to_owned().into()
pub fn obj_type(&self) -> PyTypeRef {
self.class().to_owned()
}

// int PyObject_TypeCheck(PyObject *o, PyTypeObject *type)
Expand Down
26 changes: 12 additions & 14 deletions vm/src/types/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,22 +925,20 @@ pub trait GetDescriptor: PyPayload {
#[inline]
fn _check<'a>(
zelf: &'a PyObject,
obj: Option<PyObjectRef>,
obj: PyObjectRef,
vm: &VirtualMachine,
) -> Option<(&'a Py<Self>, PyObjectRef)> {
) -> PyResult<(&'a Py<Self>, PyObjectRef)> {
// CPython descr_check
let obj = obj?;
// if (!PyObject_TypeCheck(obj, descr->d_type)) {
// PyErr_Format(PyExc_TypeError,
// "descriptor '%V' for '%.100s' objects "
// "doesn't apply to a '%.100s' object",
// descr_name((PyDescrObject *)descr), "?",
// descr->d_type->slot_name,
// obj->ob_type->slot_name);
// *pres = NULL;
// return 1;
// } else {
Some((Self::_as_pyref(zelf, vm).unwrap(), obj))
if !obj.type_check(zelf.obj_type()) {
Err(vm.new_type_error(format!(
"descriptor {:?} for {} objects doesn't apply to a {} object",
zelf,
zelf.obj_type(),
obj.obj_type()
)))
} else {
Ok((Self::_as_pyref(zelf, vm).unwrap(), obj))
}
}

#[inline]
Expand Down