Skip to content

Commit be18b53

Browse files
committed
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.
1 parent b1da169 commit be18b53

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

crates/vectorless-py/src/document.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
66
use std::sync::Arc;
77

8-
use pyo3::prelude::*;
98
use pyo3::exceptions::PyRuntimeError;
9+
use pyo3::prelude::*;
1010
use pyo3_async_runtimes::tokio::future_into_py;
1111
use tokio::sync::Mutex;
1212

@@ -380,9 +380,7 @@ impl PyDocument {
380380
future_into_py(py, async move {
381381
let num = node_id
382382
.strip_prefix('n')
383-
.ok_or_else(|| {
384-
PyRuntimeError::new_err("NodeId must start with 'n'")
385-
})?
383+
.ok_or_else(|| PyRuntimeError::new_err("NodeId must start with 'n'"))?
386384
.parse::<u64>()
387385
.map_err(|_| PyRuntimeError::new_err("Invalid NodeId"))?;
388386
let nav = nav.lock().await;
@@ -401,9 +399,7 @@ impl PyDocument {
401399
future_into_py(py, async move {
402400
let num = node_id
403401
.strip_prefix('n')
404-
.ok_or_else(|| {
405-
PyRuntimeError::new_err("NodeId must start with 'n'")
406-
})?
402+
.ok_or_else(|| PyRuntimeError::new_err("NodeId must start with 'n'"))?
407403
.parse::<u64>()
408404
.map_err(|_| PyRuntimeError::new_err("Invalid NodeId"))?;
409405
let nav = nav.lock().await;
@@ -422,9 +418,7 @@ impl PyDocument {
422418
future_into_py(py, async move {
423419
let num = node_id
424420
.strip_prefix('n')
425-
.ok_or_else(|| {
426-
PyRuntimeError::new_err("NodeId must start with 'n'")
427-
})?
421+
.ok_or_else(|| PyRuntimeError::new_err("NodeId must start with 'n'"))?
428422
.parse::<u64>()
429423
.map_err(|_| PyRuntimeError::new_err("Invalid NodeId"))?;
430424
let nav = nav.lock().await;

crates/vectorless-py/src/engine.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
//! Engine Python wrapper — async compile/forget/list_documents.
55
6-
use pyo3::prelude::*;
76
use pyo3::exceptions::PyRuntimeError;
7+
use pyo3::prelude::*;
88
use pyo3_async_runtimes::tokio::future_into_py;
99
use std::sync::Arc;
1010
use tokio::runtime::Runtime;
@@ -73,7 +73,9 @@ async fn run_load_document(engine: Arc<Engine>, doc_id: String) -> PyResult<PyDo
7373
let navigator = vectorless_primitives::DocumentNavigator::new(d);
7474
Ok(PyDocument::from_navigator(navigator))
7575
}
76-
None => Err(PyRuntimeError::new_err(format!("Document not found: {doc_id}"))),
76+
None => Err(PyRuntimeError::new_err(format!(
77+
"Document not found: {doc_id}"
78+
))),
7779
}
7880
}
7981

@@ -166,9 +168,8 @@ impl PyEngine {
166168
builder.build().await
167169
});
168170

169-
let engine = engine.map_err(|e| {
170-
PyRuntimeError::new_err(format!("Failed to create engine: {}", e))
171-
})?;
171+
let engine = engine
172+
.map_err(|e| PyRuntimeError::new_err(format!("Failed to create engine: {}", e)))?;
172173

173174
Ok(Self {
174175
inner: Arc::new(engine),

0 commit comments

Comments
 (0)