Skip to content

Commit c435587

Browse files
committed
fix: unparsing of aliased except stmt and list expressions
1 parent af08633 commit c435587

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/unparser.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,9 @@ impl Unparser {
10681068
self.write_str("[");
10691069
while let Some(expr) = elts_iter.next() {
10701070
self.unparse_expr(expr);
1071+
if elts_iter.peek().is_some() {
1072+
self.write_str(", ");
1073+
}
10711074
}
10721075
self.write_str("]");
10731076
}
@@ -1149,6 +1152,11 @@ impl Unparser {
11491152
self.write_str(" ");
11501153
self.unparse_expr(type_);
11511154
}
1155+
if let Some(name) = &node.name {
1156+
self.write_str(" as ");
1157+
self.write_str(name);
1158+
}
1159+
11521160
self.write_str(":");
11531161
self.block(|block_self| {
11541162
for stmt in &node.body {
@@ -1176,7 +1184,7 @@ impl Unparser {
11761184
|| kw_iter.peek().is_some()
11771185
|| node.kwarg.is_some()
11781186
{
1179-
self.write_str(", /");
1187+
self.write_str(", / ");
11801188
}
11811189
}
11821190

test_files/simple_try_except.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
name_1 # type: ignore # noqa: F821
88
except name_1: # type: ignore # noqa: F821
99
pass
10-
except name_4: # type: ignore # noqa: F821
10+
except name_4 as name_5: # type: ignore # noqa: F821, F841
1111
pass
1212
pass
1313
except: # noqa: E722

0 commit comments

Comments
 (0)