mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
Fix some more clippy warnings
This commit is contained in:
4 files changed
+10
-17
No files matched your search
@@ -78,6 +78,7 @@ pub trait PySliceableSequence {
|
||||
} else if step.is_positive() {
|
||||
let range = self.get_slice_range(start, stop);
|
||||
if range.start < range.end {
|
||||
#[allow(clippy::range_plus_one)]
|
||||
match step.to_i32() {
|
||||
Some(1) => Ok(self.do_slice(range)),
|
||||
Some(num) => Ok(self.do_stepped_slice(range, num as usize)),
|
||||
|
||||
@@ -75,8 +75,8 @@ fn browser_fetch(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
if let Some(headers) = headers {
|
||||
let h = request.headers();
|
||||
for (key, value) in rustpython_vm::obj::objdict::get_key_value_pairs(&headers) {
|
||||
let ref key = vm.to_str(&key)?.value;
|
||||
let ref value = vm.to_str(&value)?.value;
|
||||
let key = &vm.to_str(&key)?.value;
|
||||
let value = &vm.to_str(&value)?.value;
|
||||
h.set(key, value)
|
||||
.map_err(|err| convert::js_py_typeerror(vm, err))?;
|
||||
}
|
||||
@@ -163,9 +163,8 @@ pub struct PyPromise {
|
||||
}
|
||||
|
||||
impl PyValue for PyPromise {
|
||||
fn class(_vm: &mut VirtualMachine) -> PyObjectRef {
|
||||
// TODO
|
||||
unimplemented!()
|
||||
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
|
||||
vm.class(BROWSER_NAME, "Promise")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +182,7 @@ pub fn get_promise_value(obj: &PyObjectRef) -> Promise {
|
||||
}
|
||||
|
||||
pub fn import_promise_type(vm: &mut VirtualMachine) -> PyResult {
|
||||
match import_module(vm, PathBuf::default(), BROWSER_NAME)?.get_attr("Promise".into()) {
|
||||
match import_module(vm, PathBuf::default(), BROWSER_NAME)?.get_attr("Promise") {
|
||||
Some(promise) => Ok(promise),
|
||||
None => Err(vm.new_not_implemented_error("No Promise".to_string())),
|
||||
}
|
||||
|
||||
+3
-10
@@ -129,10 +129,7 @@ pub fn py_to_js(vm: &mut VirtualMachine, py_obj: PyObjectRef) -> JsValue {
|
||||
}
|
||||
arr.into()
|
||||
} else {
|
||||
let dumps = rustpython_vm::import::import_module(vm, std::path::PathBuf::default(), "json")
|
||||
.expect("Couldn't get json module")
|
||||
.get_attr("dumps".into())
|
||||
.expect("Couldn't get json dumps");
|
||||
let dumps = vm.class("json", "dumps");
|
||||
match vm.invoke(dumps, PyFuncArgs::new(vec![py_obj], vec![])) {
|
||||
Ok(value) => {
|
||||
let json = vm.to_pystr(&value).unwrap();
|
||||
@@ -156,7 +153,7 @@ pub fn object_entries(obj: &Object) -> impl Iterator<Item = Result<(JsValue, JsV
|
||||
pub fn pyresult_to_jsresult(vm: &mut VirtualMachine, result: PyResult) -> Result<JsValue, JsValue> {
|
||||
result
|
||||
.map(|value| py_to_js(vm, value))
|
||||
.map_err(|err| py_err_to_js_err(vm, &err).into())
|
||||
.map_err(|err| py_err_to_js_err(vm, &err))
|
||||
}
|
||||
|
||||
pub fn js_to_py(vm: &mut VirtualMachine, js_val: JsValue) -> PyObjectRef {
|
||||
@@ -229,11 +226,7 @@ pub fn js_to_py(vm: &mut VirtualMachine, js_val: JsValue) -> PyObjectRef {
|
||||
// Because `JSON.stringify(undefined)` returns undefined
|
||||
vm.get_none()
|
||||
} else {
|
||||
let loads = rustpython_vm::import::import_module(vm, std::path::PathBuf::default(), "json")
|
||||
.expect("Couldn't get json module")
|
||||
.get_attr("loads".into())
|
||||
.expect("Couldn't get json dumps");
|
||||
|
||||
let loads = vm.class("json", "dumps");
|
||||
let json = match js_sys::JSON::stringify(&js_val) {
|
||||
Ok(json) => String::from(json),
|
||||
Err(_) => return vm.get_none(),
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||
use std::rc::{Rc, Weak};
|
||||
|
||||
use js_sys::{Object, Reflect, SyntaxError, TypeError};
|
||||
use wasm_bindgen::{prelude::*, JsCast};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
use rustpython_vm::compile;
|
||||
use rustpython_vm::frame::{NameProtocol, Scope};
|
||||
|
||||
Reference in new issue
Block a user