Skip to content

Don't rewrite it in Rust. Rewrite the 5% that's slow: profile your app, port the hot functions with your coding agent, prove they behave the same. Python, JS/TS, Ruby, Java, Kotlin, Go, PHP, C/C++, C#, R.

python: show an empty set as set() in TASK.md samples (#8)

chessMan9cefd35c1245
diff --git a/src/python.rs b/src/python.rs
index 2598d48..b650063 100644
--- a/src/python.rs
+++ b/src/python.rs
@@ -304,6 +304,7 @@ fn py_value(v: &Value) -> String {
let inner: Vec<String> = items.iter().map(py_value).collect();
if inner.len() == 1 { format!("({},)", inner[0]) } else { format!("({})", inner.join(", ")) }
}
+ Some((tag, Value::Array(items))) if tag == "$set" && items.is_empty() => "set()".into(),
Some((tag, Value::Array(items))) if tag == "$set" => {
format!("{{{}}}", items.iter().map(py_value).collect::<Vec<_>>().join(", "))
}
@@ -567,6 +568,8 @@ mod tests {
py_value(&v),
r#"[None, True, "a", __import__('base64').b64decode("aGVsbG8="), (1, 2), {"k": 1.5}]"#
);
+ let sets: Value = serde_json::from_str(r#"[{"$set": []}, {"$set": [1]}, {"$dict": []}]"#).unwrap();
+ assert_eq!(py_value(&sets), "[set(), {1}, {}]");
}
#[test]