mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
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:
parent
a58bde6958
commit
8db147c09d
1 changed files with 13 additions and 7 deletions
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue