Skip to content

Commit 8c167ac

Browse files
committed
Clean up unwrapping of string objects in json.loads
1 parent 91a6989 commit 8c167ac

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

tests/snippets/json_snippet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def round_trip_test(obj):
4444

4545
class String(str): pass
4646

47+
assert "string" == json.loads(String('"string"'))
4748
assert '"string"' == json.dumps(String("string"))
4849

4950
# TODO: Uncomment and test once int/float construction is supported

vm/src/stdlib/json.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,10 @@ fn loads(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
211211
// TODO: Raise an exception for deserialisation errors
212212
let de = PyObjectDeserializer { ctx: &vm.ctx };
213213
// TODO: Support deserializing string sub-classes
214-
Ok(match string.borrow().kind {
215-
PyObjectKind::String { ref value } => de
216-
.deserialize(&mut serde_json::Deserializer::from_str(&value))
217-
.unwrap(),
218-
_ => unimplemented!("json.loads only handles strings"),
219-
})
214+
Ok(de
215+
.deserialize(&mut serde_json::Deserializer::from_str(&objstr::get_value(
216+
&string,
217+
))).unwrap())
220218
}
221219

222220
pub fn mk_module(ctx: &PyContext) -> PyObjectRef {

0 commit comments

Comments
 (0)