mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 04:55:09 +00:00
Add formatting of type alias statements (#6162)
Part of #5062 Extends https://github.com/astral-sh/ruff/pull/6161 Closes #5929
This commit is contained in:
parent
1a60d1e3c6
commit
5b2e973fa5
5 changed files with 259 additions and 80 deletions
|
@ -1,4 +1,8 @@
|
|||
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;
|
||||
|
||||
|
@ -6,12 +10,28 @@ use ruff_python_ast::StmtTypeAlias;
|
|||
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)
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue