Skip to content

Commit

Permalink
Merge pull request #305 from mozilla/python-literal-rendering
Browse files Browse the repository at this point in the history
Render all types of literal in the python bindings.
  • Loading branch information
rfk authored Sep 29, 2020
2 parents fad206a + cec3ffc commit 600882a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions uniffi_bindgen/src/bindings/python/gen_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,26 @@ mod filters {

pub fn literal_py(literal: &Literal) -> Result<String, askama::Error> {
Ok(match literal {
Literal::Boolean(v) => format!("{}", v),
Literal::Boolean(v) => {
if *v {
"True".into()
} else {
"False".into()
}
}
// use the double-quote form to match with the other languages, and quote escapes.
Literal::String(s) => format!("\"{}\"", s),
Literal::Null => "None".into(),
Literal::EmptySequence => "[]".into(),
Literal::EmptyMap => "{}".into(),

_ => panic!("Literal unsupported by python"),
Literal::Enum(v, type_) => match type_ {
Type::Enum(name) => format!("{}.{}", class_name_py(name)?, enum_name_py(v)?),
_ => panic!("Unexpected type in enum literal: {:?}", type_),
},
// TODO: render with the intended radix.
Literal::Int(i, _radix, _type_) => format!("{}", i),
Literal::UInt(i, _radix, _type_) => format!("{}", i),
Literal::Float(string, _type_) => string.clone(),
})
}

Expand Down

0 comments on commit 600882a

Please sign in to comment.