Create dedicated is_*_enabled functions for each preview style (#8988)

This commit is contained in:
Micha Reiser 2023-12-04 14:38:54 +09:00 committed by GitHub
parent 7e390d3772
commit 0bda1913d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 11 deletions

View file

@ -9,6 +9,7 @@ use crate::expression::is_expression_huggable;
use crate::expression::parentheses::{empty_parenthesized, parenthesized, Parentheses};
use crate::other::commas;
use crate::prelude::*;
use crate::preview::is_hug_parens_with_braces_and_square_brackets_enabled;
#[derive(Default)]
pub struct FormatArguments;
@ -177,8 +178,7 @@ fn is_single_argument_parenthesized(argument: &Expr, call_end: TextSize, source:
/// Hugging should only be applied to single-argument collections, like lists, or starred versions
/// of those collections.
fn is_argument_huggable(item: &Arguments, context: &PyFormatContext) -> bool {
let options = context.options();
if !options.preview().is_enabled() {
if !is_hug_parens_with_braces_and_square_brackets_enabled(context) {
return false;
}
@ -192,7 +192,7 @@ fn is_argument_huggable(item: &Arguments, context: &PyFormatContext) -> bool {
};
// If the expression itself isn't huggable, then we can't hug it.
if !is_expression_huggable(arg, options) {
if !is_expression_huggable(arg, context) {
return false;
}
@ -202,6 +202,8 @@ fn is_argument_huggable(item: &Arguments, context: &PyFormatContext) -> bool {
return false;
}
let options = context.options();
// If the expression has a trailing comma, then we can't hug it.
if options.magic_trailing_comma().is_respect()
&& commas::has_magic_trailing_comma(TextRange::new(arg.end(), item.end()), options, context)