Format single-element tuple string representations correctly

(i.e. with a trailing comma within the parentheses)
This commit is contained in:
Daniel Watkins
2018-08-05 16:47:44 -04:00
parent 36f6fb2733
commit d5ce48535d

View File

@@ -365,14 +365,18 @@ impl PyObject {
.collect::<Vec<_>>()
.join(", ")
),
PyObjectKind::Tuple { ref elements } => format!(
"({})",
elements
.iter()
.map(|elem| elem.borrow().str())
.collect::<Vec<_>>()
.join(", ")
),
PyObjectKind::Tuple { ref elements } => if elements.len() == 1 {
format!("({},)", elements[0].borrow().str())
} else {
format!(
"({})",
elements
.iter()
.map(|elem| elem.borrow().str())
.collect::<Vec<_>>()
.join(", ")
)
},
PyObjectKind::Dict { ref elements } => format!(
"{{ {} }}",
elements