Clean up unwrapping of string objects in json.loads

This commit is contained in:
Daniel Watkins
2018-09-02 16:49:50 -04:00
parent 91a6989515
commit 8c167ac4f5
2 changed files with 5 additions and 6 deletions

View File

@@ -44,6 +44,7 @@ assert [['a'], 'b'] == json.loads('[["a"], "b"]')
class String(str): pass
assert "string" == json.loads(String('"string"'))
assert '"string"' == json.dumps(String("string"))
# TODO: Uncomment and test once int/float construction is supported

View File

@@ -211,12 +211,10 @@ fn loads(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
// TODO: Raise an exception for deserialisation errors
let de = PyObjectDeserializer { ctx: &vm.ctx };
// TODO: Support deserializing string sub-classes
Ok(match string.borrow().kind {
PyObjectKind::String { ref value } => de
.deserialize(&mut serde_json::Deserializer::from_str(&value))
.unwrap(),
_ => unimplemented!("json.loads only handles strings"),
})
Ok(de
.deserialize(&mut serde_json::Deserializer::from_str(&objstr::get_value(
&string,
))).unwrap())
}
pub fn mk_module(ctx: &PyContext) -> PyObjectRef {