mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-07 21:25:08 +00:00
[flake8-comprehensions
] Handle template strings for comprehension fixes (#18710)
Essentially this PR ensures that when we do fixes like this: ```diff - t"{set(f(x) for x in foo)}" + t"{ {f(x) for x in foo} }" ``` we are correctly adding whitespace around the braces. This logic is already in place for f-strings and just needed to be generalized to interpolated strings.
This commit is contained in:
parent
10a1d9f01e
commit
ce0a32aadb
14 changed files with 919 additions and 23 deletions
|
@ -1944,6 +1944,11 @@ impl<'a> SemanticModel<'a> {
|
|||
self.flags.intersects(SemanticModelFlags::T_STRING)
|
||||
}
|
||||
|
||||
/// Return `true` if the model is in an f-string or t-string.
|
||||
pub const fn in_interpolated_string(&self) -> bool {
|
||||
self.in_f_string() || self.in_t_string()
|
||||
}
|
||||
|
||||
/// Return `true` if the model is in an f-string replacement field.
|
||||
pub const fn in_interpolated_string_replacement_field(&self) -> bool {
|
||||
self.flags
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue