mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
clearup
This commit is contained in:
@@ -477,9 +477,10 @@ impl PyObjectView<PyDict> {
|
||||
&self,
|
||||
key: K,
|
||||
vm: &VirtualMachine,
|
||||
) -> Option<PyResult> {
|
||||
) -> PyResult<Option<PyObjectRef>> {
|
||||
vm.get_method(self.to_owned().into(), "__missing__")
|
||||
.map(|methods| vm.invoke(&methods?, (key,)))
|
||||
.transpose()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -490,14 +491,11 @@ impl PyObjectView<PyDict> {
|
||||
) -> PyResult<PyObjectRef> {
|
||||
if let Some(value) = self.entries.get(vm, &key)? {
|
||||
Ok(value)
|
||||
} else if let Some(value) = self.missing_opt(key.clone(), vm) {
|
||||
value
|
||||
} else if let Some(value) = self.missing_opt(key.clone(), vm)? {
|
||||
Ok(value)
|
||||
} else {
|
||||
Err(vm.new_key_error(key.into_pyobject(vm)))
|
||||
}
|
||||
// self.entries
|
||||
// .get(vm, &key)?
|
||||
// .ok_or_else(|| vm.new_key_error(key.into_pyobject(vm)))
|
||||
}
|
||||
|
||||
/// Take a python dictionary and convert it to attributes.
|
||||
@@ -517,12 +515,11 @@ impl PyObjectView<PyDict> {
|
||||
) -> PyResult<Option<PyObjectRef>> {
|
||||
if self.exact_dict(vm) {
|
||||
self.entries.get(vm, &key)
|
||||
// FIXME: check __missing__?
|
||||
} else {
|
||||
match self.as_object().get_item(key.clone(), vm) {
|
||||
Ok(value) => Ok(Some(value)),
|
||||
Err(e) if e.isinstance(&vm.ctx.exceptions.key_error) => {
|
||||
self.missing_opt(key, vm).transpose()
|
||||
}
|
||||
Err(e) if e.isinstance(&vm.ctx.exceptions.key_error) => self.missing_opt(key, vm),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
@@ -537,13 +534,6 @@ impl PyObjectView<PyDict> {
|
||||
self.inner_getitem(key, vm)
|
||||
} else {
|
||||
self.as_object().get_item(key, vm)
|
||||
// match self.as_object().get_item(key.clone(), vm) {
|
||||
// Ok(value) => Ok(value),
|
||||
// Err(e) if e.isinstance(&vm.ctx.exceptions.key_error) => {
|
||||
// self.missing_opt(key, vm).ok_or(e)?
|
||||
// }
|
||||
// Err(e) => Err(e),
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -198,9 +198,11 @@ impl FrameRef {
|
||||
let map_to_dict = |keys: &[PyStrRef], values: &[PyCellRef]| {
|
||||
for (k, v) in itertools::zip(keys, values) {
|
||||
if let Some(value) = v.get() {
|
||||
locals.as_object().set_item(k.clone(), value, vm)?;
|
||||
locals
|
||||
.mapping()
|
||||
.ass_subscript(k.as_object(), Some(value), vm)?;
|
||||
} else {
|
||||
match locals.as_object().del_item(k.clone(), vm) {
|
||||
match locals.mapping().ass_subscript(k.as_object(), None, vm) {
|
||||
Ok(()) => {}
|
||||
Err(e) if e.isinstance(&vm.ctx.exceptions.key_error) => {}
|
||||
Err(e) => return Err(e),
|
||||
|
||||
@@ -70,7 +70,6 @@ impl PyMapping<'_> {
|
||||
}
|
||||
|
||||
pub fn methods(&self, vm: &VirtualMachine) -> &PyMappingMethods {
|
||||
// let cls = self.obj.class();
|
||||
self.methods.get_or_init(|| {
|
||||
if let Some(f) = self
|
||||
.obj
|
||||
@@ -82,20 +81,6 @@ impl PyMapping<'_> {
|
||||
PyMappingMethods::default()
|
||||
}
|
||||
})
|
||||
|
||||
// let get_methods = || {
|
||||
// if let Some(f) = cls.mro_find_map(|cls| cls.slots.as_mapping.load()) {
|
||||
// f(self.obj, vm)
|
||||
// } else {
|
||||
// PyMappingMethods::default()
|
||||
// }
|
||||
// };
|
||||
|
||||
// if cls.slots.flags.has_feature(PyTypeFlags::HEAPTYPE) {
|
||||
// &get_methods()
|
||||
// } else {
|
||||
// self.methods.get_or_init(get_methods)
|
||||
// }
|
||||
}
|
||||
|
||||
pub fn length_opt(&self, vm: &VirtualMachine) -> Option<PyResult<usize>> {
|
||||
|
||||
@@ -4,7 +4,7 @@ pub(crate) use _winapi::make_module;
|
||||
#[pymodule]
|
||||
mod _winapi {
|
||||
use crate::{
|
||||
builtins::{PyListRef, PyStrRef},
|
||||
builtins::PyStrRef,
|
||||
function::{ArgMapping, IntoPyException, OptionalArg},
|
||||
stdlib::os::errno_err,
|
||||
PyObjectRef, PyResult, PySequence, TryFromObject, VirtualMachine,
|
||||
|
||||
Reference in New Issue
Block a user