mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-22 04:25:11 +00:00
Type alias stub for formatter (#5880)
**Summary** This replaces the `todo!()` with a type alias stub in the
formatter. I added the tests from
704eb40108/parser/src/parser.rs (L901-L936)
as ruff python formatter tests.
**Test Plan** None, testing is part of the actual implementation
This commit is contained in:
parent
a51606a10a
commit
a227775f62
21 changed files with 748 additions and 1 deletions
|
@ -361,6 +361,46 @@ impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::StmtDelete {
|
|||
}
|
||||
}
|
||||
|
||||
impl FormatRule<ast::StmtTypeAlias, PyFormatContext<'_>>
|
||||
for crate::statement::stmt_type_alias::FormatStmtTypeAlias
|
||||
{
|
||||
#[inline]
|
||||
fn fmt(
|
||||
&self,
|
||||
node: &ast::StmtTypeAlias,
|
||||
f: &mut Formatter<PyFormatContext<'_>>,
|
||||
) -> FormatResult<()> {
|
||||
FormatNodeRule::<ast::StmtTypeAlias>::fmt(self, node, f)
|
||||
}
|
||||
}
|
||||
impl<'ast> AsFormat<PyFormatContext<'ast>> for ast::StmtTypeAlias {
|
||||
type Format<'a> = FormatRefWithRule<
|
||||
'a,
|
||||
ast::StmtTypeAlias,
|
||||
crate::statement::stmt_type_alias::FormatStmtTypeAlias,
|
||||
PyFormatContext<'ast>,
|
||||
>;
|
||||
fn format(&self) -> Self::Format<'_> {
|
||||
FormatRefWithRule::new(
|
||||
self,
|
||||
crate::statement::stmt_type_alias::FormatStmtTypeAlias::default(),
|
||||
)
|
||||
}
|
||||
}
|
||||
impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::StmtTypeAlias {
|
||||
type Format = FormatOwnedWithRule<
|
||||
ast::StmtTypeAlias,
|
||||
crate::statement::stmt_type_alias::FormatStmtTypeAlias,
|
||||
PyFormatContext<'ast>,
|
||||
>;
|
||||
fn into_format(self) -> Self::Format {
|
||||
FormatOwnedWithRule::new(
|
||||
self,
|
||||
crate::statement::stmt_type_alias::FormatStmtTypeAlias::default(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl FormatRule<ast::StmtAssign, PyFormatContext<'_>>
|
||||
for crate::statement::stmt_assign::FormatStmtAssign
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@ pub(crate) mod stmt_raise;
|
|||
pub(crate) mod stmt_return;
|
||||
pub(crate) mod stmt_try;
|
||||
pub(crate) mod stmt_try_star;
|
||||
pub(crate) mod stmt_type_alias;
|
||||
pub(crate) mod stmt_while;
|
||||
pub(crate) mod stmt_with;
|
||||
pub(crate) mod suite;
|
||||
|
@ -64,7 +65,7 @@ impl FormatRule<Stmt, PyFormatContext<'_>> for FormatStmt {
|
|||
Stmt::Pass(x) => x.format().fmt(f),
|
||||
Stmt::Break(x) => x.format().fmt(f),
|
||||
Stmt::Continue(x) => x.format().fmt(f),
|
||||
Stmt::TypeAlias(_) => todo!(),
|
||||
Stmt::TypeAlias(x) => x.format().fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::StmtTypeAlias;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtTypeAlias;
|
||||
|
||||
impl FormatNodeRule<StmtTypeAlias> for FormatStmtTypeAlias {
|
||||
fn fmt_fields(&self, _item: &StmtTypeAlias, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(
|
||||
f,
|
||||
[not_yet_implemented_custom_text(
|
||||
"type NOT_YET_IMPLEMENTED_type_alias = int"
|
||||
)]
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue