Format Identifier (#5255)

This commit is contained in:
Micha Reiser 2023-06-21 17:35:37 +02:00 committed by GitHub
parent 6155fd647d
commit e47aa468d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 13 deletions

View file

@ -1,7 +1,6 @@
use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::write;
use ruff_text_size::{TextLen, TextRange};
use rustpython_parser::ast::Arg;
#[derive(Default)]
@ -10,21 +9,13 @@ pub struct FormatArg;
impl FormatNodeRule<Arg> for FormatArg {
fn fmt_fields(&self, item: &Arg, f: &mut PyFormatter) -> FormatResult<()> {
let Arg {
range,
range: _,
arg,
annotation,
type_comment: _,
} = item;
write!(
f,
[
// The name of the argument
source_text_slice(
TextRange::at(range.start(), arg.text_len()),
ContainsNewlines::No
)
]
)?;
arg.format().fmt(f)?;
if let Some(annotation) = annotation {
write!(f, [text(":"), space(), annotation.format()])?;