-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add formatting of type alias statements (#6162)
- Loading branch information
Showing
5 changed files
with
260 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 25 additions & 5 deletions
30
crates/ruff_python_formatter/src/statement/stmt_type_alias.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,37 @@ | ||
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter}; | ||
use crate::expression::maybe_parenthesize_expression; | ||
use crate::expression::parentheses::Parenthesize; | ||
use crate::AsFormat; | ||
use crate::{FormatNodeRule, PyFormatter}; | ||
use ruff_formatter::prelude::{space, text}; | ||
use ruff_formatter::{write, Buffer, FormatResult}; | ||
use ruff_python_ast::StmtTypeAlias; | ||
|
||
#[derive(Default)] | ||
pub struct FormatStmtTypeAlias; | ||
|
||
impl FormatNodeRule<StmtTypeAlias> for FormatStmtTypeAlias { | ||
fn fmt_fields(&self, _item: &StmtTypeAlias, f: &mut PyFormatter) -> FormatResult<()> { | ||
fn fmt_fields(&self, item: &StmtTypeAlias, f: &mut PyFormatter) -> FormatResult<()> { | ||
let StmtTypeAlias { | ||
name, | ||
type_params, | ||
value, | ||
range: _, | ||
} = item; | ||
|
||
write!(f, [text("type"), space(), name.as_ref().format()])?; | ||
|
||
if let Some(type_params) = type_params { | ||
write!(f, [type_params.format()])?; | ||
} | ||
|
||
write!( | ||
f, | ||
[not_yet_implemented_custom_text( | ||
"type NOT_YET_IMPLEMENTED_type_alias = int" | ||
)] | ||
[ | ||
space(), | ||
text("="), | ||
space(), | ||
maybe_parenthesize_expression(value, item, Parenthesize::IfBreaks) | ||
] | ||
) | ||
} | ||
} |
50 changes: 0 additions & 50 deletions
50
...es/ruff_python_formatter/tests/snapshots/black_compatibility@py_312__type_aliases.py.snap
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.