Generator should add a newline before type statement (#11720)

## Summary

This PR fixes a bug where the `Generator` wouldn't add a newline before
a type alias statement. This is because it wasn't using the `statement`
macro which takes care of the newline.

Without this fix, a code like:
```py
type X = int
type Y = str
```

The generator would produce:
```py
type X = inttype Y = str
```

## Test Plan

Add a test case.
This commit is contained in:
Dhruv Manilawala 2024-06-03 18:44:21 +05:30 committed by GitHub
parent a58bde6958
commit 8db147c09d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -482,13 +482,15 @@ impl<'a> Generator<'a> {
type_params,
value,
}) => {
self.p("type ");
self.unparse_expr(name, precedence::MAX);
if let Some(type_params) = type_params {
self.unparse_type_params(type_params);
}
self.p(" = ");
self.unparse_expr(value, precedence::ASSIGN);
statement!({
self.p("type ");
self.unparse_expr(name, precedence::MAX);
if let Some(type_params) = type_params {
self.unparse_type_params(type_params);
}
self.p(" = ");
self.unparse_expr(value, precedence::ASSIGN);
});
}
Stmt::Raise(ast::StmtRaise {
exc,
@ -1634,6 +1636,10 @@ except* Exception as e:
return 2
case 4 as y:
return y"
);
assert_round_trip!(
r"type X = int
type Y = str"
);
assert_eq!(round_trip(r"x = (1, 2, 3)"), r"x = 1, 2, 3");
assert_eq!(round_trip(r"-(1) + ~(2) + +(3)"), r"-1 + ~2 + +3");