add preview function taking a PreviewMode

This commit is contained in:
Brent Westbrook 2025-12-10 12:19:55 -05:00
parent 9f9b76b035
commit a8bebaa681
No known key found for this signature in database
2 changed files with 7 additions and 3 deletions

View File

@ -19,6 +19,7 @@ use crate::other::parameters::{
assign_argument_separator_comment_placement, find_parameter_separators, assign_argument_separator_comment_placement, find_parameter_separators,
}; };
use crate::pattern::pattern_match_sequence::SequenceType; use crate::pattern::pattern_match_sequence::SequenceType;
use crate::preview::is_parenthesize_lambda_bodies_enabled_preview;
/// Manually attach comments to nodes that the default placement gets wrong. /// Manually attach comments to nodes that the default placement gets wrong.
pub(super) fn place_comment<'a>( pub(super) fn place_comment<'a>(
@ -1885,7 +1886,7 @@ fn handle_lambda_comment<'a>(
return CommentPlacement::Default(comment); return CommentPlacement::Default(comment);
} }
return if preview.is_enabled() { return if is_parenthesize_lambda_bodies_enabled_preview(preview) {
CommentPlacement::leading(&*lambda.body, comment) CommentPlacement::leading(&*lambda.body, comment)
} else { } else {
CommentPlacement::dangling(comment.enclosing_node(), comment) CommentPlacement::dangling(comment.enclosing_node(), comment)
@ -1918,7 +1919,7 @@ fn handle_lambda_comment<'a>(
return CommentPlacement::Default(comment); return CommentPlacement::Default(comment);
} }
return if preview.is_enabled() { return if is_parenthesize_lambda_bodies_enabled_preview(preview) {
CommentPlacement::leading(&*lambda.body, comment) CommentPlacement::leading(&*lambda.body, comment)
} else { } else {
CommentPlacement::dangling(comment.enclosing_node(), comment) CommentPlacement::dangling(comment.enclosing_node(), comment)

View File

@ -5,7 +5,7 @@
//! for which specific feature this preview check is for. Having named functions simplifies the promotion: //! for which specific feature this preview check is for. Having named functions simplifies the promotion:
//! Simply delete the function and let Rust tell you which checks you have to remove. //! Simply delete the function and let Rust tell you which checks you have to remove.
use crate::PyFormatContext; use crate::{PreviewMode, PyFormatContext};
/// Returns `true` if the [`hug_parens_with_braces_and_square_brackets`](https://github.com/astral-sh/ruff/issues/8279) preview style is enabled. /// Returns `true` if the [`hug_parens_with_braces_and_square_brackets`](https://github.com/astral-sh/ruff/issues/8279) preview style is enabled.
pub(crate) const fn is_hug_parens_with_braces_and_square_brackets_enabled( pub(crate) const fn is_hug_parens_with_braces_and_square_brackets_enabled(
@ -59,3 +59,6 @@ pub(crate) const fn is_avoid_parens_for_long_as_captures_enabled(
pub(crate) const fn is_parenthesize_lambda_bodies_enabled(context: &PyFormatContext) -> bool { pub(crate) const fn is_parenthesize_lambda_bodies_enabled(context: &PyFormatContext) -> bool {
context.is_preview() context.is_preview()
} }
pub(crate) const fn is_parenthesize_lambda_bodies_enabled_preview(preview: PreviewMode) -> bool {
preview.is_enabled()
}