mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Clean up unwrapping of string objects in json.loads
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user