Skip to content

Commit 67f8c02

Browse files
cleanup
1 parent 713edc5 commit 67f8c02

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

vm/src/obj/objbool.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::objstr::PyString;
12
use super::objtype;
23
use crate::pyobject::{
34
IntoPyObject, PyContext, PyFuncArgs, PyObjectPayload, PyObjectRef, PyResult, TypeProtocol,
@@ -12,13 +13,14 @@ impl IntoPyObject for bool {
1213
}
1314

1415
pub fn boolval(vm: &mut VirtualMachine, obj: PyObjectRef) -> Result<bool, PyObjectRef> {
16+
if let Some(s) = obj.payload::<PyString>() {
17+
return Ok(!s.value.is_empty());
18+
}
1519
let result = match obj.payload {
1620
PyObjectPayload::Integer { ref value } => !value.is_zero(),
1721
PyObjectPayload::Float { value } => value != 0.0,
1822
PyObjectPayload::Sequence { ref elements } => !elements.borrow().is_empty(),
1923
PyObjectPayload::Dict { ref elements } => !elements.borrow().is_empty(),
20-
// FIXME
21-
//PyObjectPayload::String { ref value } => !value.is_empty(),
2224
PyObjectPayload::None { .. } => false,
2325
_ => {
2426
if let Ok(f) = vm.get_method(obj.clone(), "__bool__") {

vm/src/stdlib/json.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ use serde::de::{DeserializeSeed, Visitor};
55
use serde::ser::{SerializeMap, SerializeSeq};
66
use serde_json;
77

8-
use crate::obj::{objbool, objdict, objfloat, objint, objsequence, objstr, objtype};
8+
use crate::obj::{
9+
objbool, objdict, objfloat, objint, objsequence,
10+
objstr::{self, PyString},
11+
objtype,
12+
};
913
use crate::pyobject::{
1014
create_type, DictProtocol, PyContext, PyFuncArgs, PyObjectPayload, PyObjectRef, PyResult,
1115
TypeProtocol,
@@ -167,9 +171,8 @@ impl<'de> Visitor<'de> for PyObjectDeserializer<'de> {
167171
// than wrapping the given object up and then unwrapping it to determine whether or
168172
// not it is a string
169173
while let Some((key_obj, value)) = access.next_entry_seed(self.clone(), self.clone())? {
170-
let key: String = match key_obj.payload {
171-
// FIXME
172-
// PyObjectPayload::String { ref value } => value.clone(),
174+
let key: String = match key_obj.payload::<PyString>() {
175+
Some(PyString { ref value }) => value.clone(),
173176
_ => unimplemented!("map keys must be strings"),
174177
};
175178
self.vm.ctx.set_item(&dict, &key, value);

0 commit comments

Comments
 (0)