[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:
Dylan 2025-06-19 16:23:46 -05:00 committed by GitHub
parent 10a1d9f01e
commit ce0a32aadb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 919 additions and 23 deletions

View file

@ -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