Skip to content

Commit

Permalink
fix(unparser): fixed precedence for subscriptions (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvllmr authored Feb 19, 2025
1 parent c5301b2 commit 0cf4e19
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/unparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,9 @@ impl Unparser {
self.write_str(&node.attr);
}
fn unparse_expr_subscript(&mut self, node: &ExprSubscript<TextRange>) {
self.unparse_expr(&node.value);
self.with_precedence(Precedence::Atom, |prec_self| {
prec_self.unparse_expr(&node.value);
});
self.write_str("[");
self.unparse_expr(&node.slice);
self.write_str("]");
Expand Down
2 changes: 2 additions & 0 deletions test_files/precedence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
reduce = "abcdefhijklmnopqrstuvwxyz"
reduce_list = (list(reduce) + [None] * 5)[:5]

0 comments on commit 0cf4e19

Please sign in to comment.