Skip to content

Commit

Permalink
Fix precedence of annotated assignments in generator
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Sep 3, 2023
1 parent 9c3b2c3 commit aa4f483
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/ruff_python_codegen/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl<'a> Generator<'a> {
self.unparse_expr(target, precedence::ANN_ASSIGN);
self.p_if(need_parens, ")");
self.p(": ");
self.unparse_expr(annotation, precedence::ANN_ASSIGN);
self.unparse_expr(annotation, precedence::COMMA);
if let Some(value) = value {
self.p(" = ");
self.unparse_expr(value, precedence::COMMA);
Expand Down Expand Up @@ -1636,6 +1636,10 @@ class Foo:
assert_round_trip!(r#"[n * 2 for n in range(10)]"#);
assert_round_trip!(r#"{n * 2 for n in range(10)}"#);
assert_round_trip!(r#"{i: n * 2 for i, n in enumerate(range(10))}"#);
assert_round_trip!(
"class SchemaItem(NamedTuple):
fields: ((\"property_key\", str),)"
);

// Type aliases
assert_round_trip!(r#"type Foo = int | str"#);
Expand Down

0 comments on commit aa4f483

Please sign in to comment.