From be18b53adcaad91c4b3a29d56e5cd097412dc84e Mon Sep 17 00:00:00 2001 From: zTgx <747674262@qq.com> Date: Wed, 29 Apr 2026 18:30:27 +0800 Subject: [PATCH] refactor(python): reorder imports and improve error handling formatting Reorder pyo3 imports in document.rs and engine.rs for consistency. Format error handling code to stay within 100 character line limits and improve readability. --- crates/vectorless-py/src/document.rs | 14 ++++---------- crates/vectorless-py/src/engine.rs | 11 ++++++----- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/crates/vectorless-py/src/document.rs b/crates/vectorless-py/src/document.rs index 1145893..9a571aa 100644 --- a/crates/vectorless-py/src/document.rs +++ b/crates/vectorless-py/src/document.rs @@ -5,8 +5,8 @@ use std::sync::Arc; -use pyo3::prelude::*; use pyo3::exceptions::PyRuntimeError; +use pyo3::prelude::*; use pyo3_async_runtimes::tokio::future_into_py; use tokio::sync::Mutex; @@ -380,9 +380,7 @@ impl PyDocument { future_into_py(py, async move { let num = node_id .strip_prefix('n') - .ok_or_else(|| { - PyRuntimeError::new_err("NodeId must start with 'n'") - })? + .ok_or_else(|| PyRuntimeError::new_err("NodeId must start with 'n'"))? .parse::() .map_err(|_| PyRuntimeError::new_err("Invalid NodeId"))?; let nav = nav.lock().await; @@ -401,9 +399,7 @@ impl PyDocument { future_into_py(py, async move { let num = node_id .strip_prefix('n') - .ok_or_else(|| { - PyRuntimeError::new_err("NodeId must start with 'n'") - })? + .ok_or_else(|| PyRuntimeError::new_err("NodeId must start with 'n'"))? .parse::() .map_err(|_| PyRuntimeError::new_err("Invalid NodeId"))?; let nav = nav.lock().await; @@ -422,9 +418,7 @@ impl PyDocument { future_into_py(py, async move { let num = node_id .strip_prefix('n') - .ok_or_else(|| { - PyRuntimeError::new_err("NodeId must start with 'n'") - })? + .ok_or_else(|| PyRuntimeError::new_err("NodeId must start with 'n'"))? .parse::() .map_err(|_| PyRuntimeError::new_err("Invalid NodeId"))?; let nav = nav.lock().await; diff --git a/crates/vectorless-py/src/engine.rs b/crates/vectorless-py/src/engine.rs index 229016b..065af2f 100644 --- a/crates/vectorless-py/src/engine.rs +++ b/crates/vectorless-py/src/engine.rs @@ -3,8 +3,8 @@ //! Engine Python wrapper — async compile/forget/list_documents. -use pyo3::prelude::*; use pyo3::exceptions::PyRuntimeError; +use pyo3::prelude::*; use pyo3_async_runtimes::tokio::future_into_py; use std::sync::Arc; use tokio::runtime::Runtime; @@ -73,7 +73,9 @@ async fn run_load_document(engine: Arc, doc_id: String) -> PyResult Err(PyRuntimeError::new_err(format!("Document not found: {doc_id}"))), + None => Err(PyRuntimeError::new_err(format!( + "Document not found: {doc_id}" + ))), } } @@ -166,9 +168,8 @@ impl PyEngine { builder.build().await }); - let engine = engine.map_err(|e| { - PyRuntimeError::new_err(format!("Failed to create engine: {}", e)) - })?; + let engine = engine + .map_err(|e| PyRuntimeError::new_err(format!("Failed to create engine: {}", e)))?; Ok(Self { inner: Arc::new(engine),