mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
Replace dynamic implicit concatenation detection with parser flag (#6513)
## Summary In https://github.com/astral-sh/ruff/pull/6512, we added a flag to the AST to mark implicitly-concatenated string expressions. This PR makes use of that flag to remove the `is_implicit_concatenation` method. ## Test Plan `cargo test`
This commit is contained in:
parent
40407dcce5
commit
a7cf8f0b77
8 changed files with 52 additions and 150 deletions
|
@ -1,9 +1,7 @@
|
|||
use ruff_python_ast::{Constant, ExprConstant, Ranged};
|
||||
use ruff_text_size::{TextLen, TextRange};
|
||||
|
||||
use ruff_formatter::FormatRuleWithOptions;
|
||||
use ruff_python_ast::node::AnyNodeRef;
|
||||
use ruff_python_ast::str::is_implicit_concatenation;
|
||||
use ruff_python_ast::{Constant, ExprConstant, Ranged};
|
||||
use ruff_text_size::{TextLen, TextRange};
|
||||
|
||||
use crate::expression::number::{FormatComplex, FormatFloat, FormatInt};
|
||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||
|
@ -80,10 +78,9 @@ impl NeedsParentheses for ExprConstant {
|
|||
_parent: AnyNodeRef,
|
||||
context: &PyFormatContext,
|
||||
) -> OptionalParentheses {
|
||||
if self.value.is_str() || self.value.is_bytes() {
|
||||
let contents = context.locator().slice(self.range());
|
||||
if self.value.is_implicit_concatenated() {
|
||||
// Don't wrap triple quoted strings
|
||||
if is_multiline_string(self, context.source()) || !is_implicit_concatenation(contents) {
|
||||
if is_multiline_string(self, context.source()) {
|
||||
OptionalParentheses::Never
|
||||
} else {
|
||||
OptionalParentheses::Multiline
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue