mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
Fix ArgWithDefault comments handling (#5204)
This commit is contained in:
parent
fde5dbc9aa
commit
e520a3a721
17 changed files with 73 additions and 69 deletions
|
@ -1,6 +1,5 @@
|
|||
use rustpython_parser::ast::ArgWithDefault;
|
||||
|
||||
use ruff_formatter::write;
|
||||
use rustpython_parser::ast::ArgWithDefault;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::FormatNodeRule;
|
||||
|
@ -20,7 +19,7 @@ impl FormatNodeRule<ArgWithDefault> for FormatArgWithDefault {
|
|||
|
||||
if let Some(default) = default {
|
||||
let space = def.annotation.is_some().then_some(space());
|
||||
write!(f, [space, text("="), space, default.format()])?;
|
||||
write!(f, [space, text("="), space, group(&default.format())])?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -34,14 +34,9 @@ impl FormatNodeRule<Arguments> for FormatArguments {
|
|||
let mut last_node: Option<AnyNodeRef> = None;
|
||||
|
||||
for arg_with_default in posonlyargs {
|
||||
joiner.entry(&arg_with_default.into_format());
|
||||
joiner.entry(&arg_with_default.format());
|
||||
|
||||
last_node = Some(
|
||||
arg_with_default
|
||||
.default
|
||||
.as_deref()
|
||||
.map_or_else(|| (&arg_with_default.def).into(), AnyNodeRef::from),
|
||||
);
|
||||
last_node = Some(arg_with_default.into());
|
||||
}
|
||||
|
||||
if !posonlyargs.is_empty() {
|
||||
|
@ -49,14 +44,9 @@ impl FormatNodeRule<Arguments> for FormatArguments {
|
|||
}
|
||||
|
||||
for arg_with_default in args {
|
||||
joiner.entry(&arg_with_default.into_format());
|
||||
joiner.entry(&arg_with_default.format());
|
||||
|
||||
last_node = Some(
|
||||
arg_with_default
|
||||
.default
|
||||
.as_deref()
|
||||
.map_or_else(|| (&arg_with_default.def).into(), AnyNodeRef::from),
|
||||
);
|
||||
last_node = Some(arg_with_default.into());
|
||||
}
|
||||
|
||||
// kw only args need either a `*args` ahead of them capturing all var args or a `*`
|
||||
|
@ -74,14 +64,9 @@ impl FormatNodeRule<Arguments> for FormatArguments {
|
|||
}
|
||||
|
||||
for arg_with_default in kwonlyargs {
|
||||
joiner.entry(&arg_with_default.into_format());
|
||||
joiner.entry(&arg_with_default.format());
|
||||
|
||||
last_node = Some(
|
||||
arg_with_default
|
||||
.default
|
||||
.as_deref()
|
||||
.map_or_else(|| (&arg_with_default.def).into(), AnyNodeRef::from),
|
||||
);
|
||||
last_node = Some(arg_with_default.into());
|
||||
}
|
||||
|
||||
if let Some(kwarg) = kwarg {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue