Skip to content

Commit

Permalink
fix: clippy warning on multiline string in hydro_cli, py_udf
Browse files Browse the repository at this point in the history
  • Loading branch information
MingweiSamuel committed Sep 29, 2023
1 parent 9646ca0 commit bf952b4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions hydro_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ pub fn _core(py: Python<'_>, module: &PyModule) -> PyResult<()> {
.set(
PyModule::from_code(
py,
r#"
"
import asyncio
async def coroutine_to_safely_cancellable(c, cancel_token):
try:
Expand All @@ -791,7 +791,7 @@ async def coroutine_to_safely_cancellable(c, cancel_token):
cancel_token.safe_cancel()
await c
raise asyncio.CancelledError()
"#,
",
"converters",
"converters",
)?
Expand Down
7 changes: 4 additions & 3 deletions hydroflow/examples/python_udf/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ async fn main() {
)
// Map to tuples
-> map(|x| (x, 1))
-> py_udf(r#"
-> py_udf("
def add(a, b):
return a + 1
"#, "add")
return a + 1",
"add"
)
-> map(|x: PyResult<Py<PyAny>>| -> i32 {Python::with_gil(|py| {
x.unwrap().extract(py).unwrap()
})})
Expand Down
12 changes: 6 additions & 6 deletions hydroflow/tests/surface_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ pub fn test_python_basic() {
let mut hf = hydroflow_syntax! {
source_iter(0..10)
-> map(|x| (x,))
-> py_udf(r#"
-> py_udf("
def fib(n):
if n < 2:
return n
else:
return fib(n - 2) + fib(n - 1)
"#, "fib")
", "fib")
-> map(|x: PyResult<Py<PyAny>>| Python::with_gil(|py| {
usize::extract(x.unwrap().as_ref(py)).unwrap()
}))
Expand All @@ -30,10 +30,10 @@ def fib(n):
pub fn test_python_too_many_args() {
let mut hf = hydroflow_syntax! {
source_iter([(5,)])
-> py_udf(r#"
-> py_udf("
def add(a, b):
return a + b
"#, "add")
", "add")
-> map(PyResult::<Py<PyAny>>::unwrap_err)
-> map(|py_err| py_err.to_string())
-> assert_eq(["TypeError: add() missing 1 required positional argument: 'b'"]);
Expand All @@ -47,10 +47,10 @@ def add(a, b):
pub fn test_python_two_args() {
let mut hf = hydroflow_syntax! {
source_iter([(5,1)])
-> py_udf(r#"
-> py_udf("
def add(a, b):
return a + b
"#, "add")
", "add")
-> map(|x: PyResult<Py<PyAny>>| Python::with_gil(|py| {
usize::extract(x.unwrap().as_ref(py)).unwrap()
}))
Expand Down
8 changes: 4 additions & 4 deletions hydroflow_lang/src/graph/ops/py_udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ use super::{
///
/// source_iter(0..10)
/// -> map(|x| (x,))
/// -> py_udf(r#"
/// -> py_udf("
/// def fib(n):
/// if n < 2:
/// return n
/// else:
/// return fib(n - 2) + fib(n - 1)
/// "#, "fib")
/// ", "fib")
/// -> map(|x: PyResult<Py<PyAny>>| Python::with_gil(|py| {
/// usize::extract(x.unwrap().as_ref(py)).unwrap()
/// }))
Expand All @@ -41,10 +41,10 @@ use super::{
/// use pyo3::prelude::*;
///
/// source_iter([(5,1)])
/// -> py_udf(r#"
/// -> py_udf("
/// def add(a, b):
/// return a + b
/// "#, "add")
/// ", "add")
/// -> map(|x: PyResult<Py<PyAny>>| Python::with_gil(|py| {
/// usize::extract(x.unwrap().as_ref(py)).unwrap()
/// }))
Expand Down

0 comments on commit bf952b4

Please sign in to comment.