Skip to content

Commit 801eebf

Browse files
committed
Fix printing of 1-tuples and imports.
1 parent 8d94f42 commit 801eebf

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/visitors/printer.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,13 @@ fn format_expr(e: &Expression) -> String {
514514
format!("{{{}}}", comma_join(v.iter().map(format_setitem))),
515515
Expression::ListLiteral(ref v) =>
516516
format!("[{}]", comma_join(v.iter().map(format_setitem))),
517-
Expression::TupleLiteral(ref v) =>
518-
format!("({})", comma_join(v.iter().map(format_setitem))),
517+
Expression::TupleLiteral(ref v) => {
518+
match v.len() {
519+
0 => "()".to_string(),
520+
1 => format!("({},)", format_setitem(&v[0])),
521+
_ => format!("({})", comma_join(v.iter().map(format_setitem))),
522+
}
523+
},
519524

520525
Expression::DictComp(e, ref comp) =>
521526
format!("{{{} {}}}", format_dictitem(e), space_join(comp.iter().map(format_comp))),
@@ -612,13 +617,15 @@ fn format_import(imp: &Import) -> String {
612617
},
613618
Import::Import { ref names } => {
614619
s.push_str("import ");
615-
for (name, as_name) in names {
616-
s.push_str(&format_dotted_name(name));
620+
s.push_str(&comma_join(names.iter().map(|(name, as_name)| {
621+
let mut s2 = String::new();
622+
s2.push_str(&format_dotted_name(name));
617623
if let Some(as_name) = as_name {
618-
s.push_str(" as ");
619-
s.push_str(as_name);
624+
s2.push_str(" as ");
625+
s2.push_str(as_name);
620626
}
621-
}
627+
s2
628+
})));
622629
}
623630
}
624631
s

0 commit comments

Comments
 (0)