Skip to content

Commit

Permalink
Use BestFits for non-call chain call expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Aug 23, 2023
1 parent 19772c7 commit cb56080
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 1 addition & 4 deletions crates/ruff_python_formatter/src/expression/expr_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ impl NeedsParentheses for ExprCall {
{
OptionalParentheses::Multiline
} else {
match self.func.needs_parentheses(self.into(), context) {
OptionalParentheses::BestFit => OptionalParentheses::IfFits,
parentheses => parentheses,
}
self.func.needs_parentheses(self.into(), context)
}
}
}
8 changes: 5 additions & 3 deletions crates/ruff_python_formatter/src/expression/expr_constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ impl NeedsParentheses for ExprConstant {
_parent: AnyNodeRef,
context: &PyFormatContext,
) -> OptionalParentheses {
if is_multiline_string(self, context.source()) {
if is_multiline_string(self, context.source())
|| self.value.is_none()
|| self.value.is_bool()
|| self.value.is_ellipsis()
{
OptionalParentheses::Never
} else if self.value.is_implicit_concatenated() {
OptionalParentheses::Multiline
} else if self.value.is_none() | self.value.is_bool() || self.value.is_ellipsis() {
OptionalParentheses::Never
} else {
let text_len = context.source()[self.range].len();

Expand Down
2 changes: 2 additions & 0 deletions crates/ruff_python_formatter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
extern crate core;

use thiserror::Error;

use ruff_formatter::format_element::tag;
Expand Down

0 comments on commit cb56080

Please sign in to comment.