diff --git a/crates/ruff/resources/test/fixtures/pyupgrade/UP032_0.py b/crates/ruff/resources/test/fixtures/pyupgrade/UP032_0.py index 28cc06427d..6f1bef19ab 100644 --- a/crates/ruff/resources/test/fixtures/pyupgrade/UP032_0.py +++ b/crates/ruff/resources/test/fixtures/pyupgrade/UP032_0.py @@ -124,6 +124,22 @@ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 111111 ) +"{}".format( + [ + 1, + 2, + 3, + ] +) + +"{a}".format( + a=[ + 1, + 2, + 3, + ] +) + async def c(): return "{}".format(await 3) diff --git a/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs b/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs index 9f9954719b..747518618b 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/f_strings.rs @@ -67,7 +67,9 @@ impl<'a> FormatSummaryValues<'a> { let mut extracted_kwargs: FxHashMap<&str, &Expr> = FxHashMap::default(); if let Expr::Call(ast::ExprCall { args, keywords, .. }) = expr { for arg in args { - if contains_invalids(locator.slice(arg.range())) { + if contains_invalids(locator.slice(arg.range())) + || locator.contains_line_break(arg.range()) + { return None; } extracted_args.push(arg); @@ -79,7 +81,9 @@ impl<'a> FormatSummaryValues<'a> { range: _, } = keyword; if let Some(key) = arg { - if contains_invalids(locator.slice(value.range())) { + if contains_invalids(locator.slice(value.range())) + || locator.contains_line_break(value.range()) + { return None; } extracted_kwargs.insert(key, value); diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP032_0.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP032_0.py.snap index 2ae81f60ba..7bda7079a0 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP032_0.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP032_0.py.snap @@ -655,54 +655,54 @@ UP032_0.py:69:85: UP032 [*] Use f-string instead of `format` call 75 73 | ### 76 74 | # Non-errors -UP032_0.py:136:11: UP032 [*] Use f-string instead of `format` call +UP032_0.py:152:11: UP032 [*] Use f-string instead of `format` call | -135 | def d(osname, version, release): -136 | return"{}-{}.{}".format(osname, version, release) +151 | def d(osname, version, release): +152 | return"{}-{}.{}".format(osname, version, release) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP032 | = help: Convert to f-string ℹ Suggested fix -133 133 | -134 134 | -135 135 | def d(osname, version, release): -136 |- return"{}-{}.{}".format(osname, version, release) - 136 |+ return f"{osname}-{version}.{release}" -137 137 | -138 138 | -139 139 | def e(): +149 149 | +150 150 | +151 151 | def d(osname, version, release): +152 |- return"{}-{}.{}".format(osname, version, release) + 152 |+ return f"{osname}-{version}.{release}" +153 153 | +154 154 | +155 155 | def e(): -UP032_0.py:140:10: UP032 [*] Use f-string instead of `format` call +UP032_0.py:156:10: UP032 [*] Use f-string instead of `format` call | -139 | def e(): -140 | yield"{}".format(1) +155 | def e(): +156 | yield"{}".format(1) | ^^^^^^^^^^^^^^ UP032 | = help: Convert to f-string ℹ Suggested fix -137 137 | -138 138 | -139 139 | def e(): -140 |- yield"{}".format(1) - 140 |+ yield f"{1}" -141 141 | -142 142 | -143 143 | assert"{}".format(1) +153 153 | +154 154 | +155 155 | def e(): +156 |- yield"{}".format(1) + 156 |+ yield f"{1}" +157 157 | +158 158 | +159 159 | assert"{}".format(1) -UP032_0.py:143:7: UP032 [*] Use f-string instead of `format` call +UP032_0.py:159:7: UP032 [*] Use f-string instead of `format` call | -143 | assert"{}".format(1) +159 | assert"{}".format(1) | ^^^^^^^^^^^^^^ UP032 | = help: Convert to f-string ℹ Suggested fix -140 140 | yield"{}".format(1) -141 141 | -142 142 | -143 |-assert"{}".format(1) - 143 |+assert f"{1}" +156 156 | yield"{}".format(1) +157 157 | +158 158 | +159 |-assert"{}".format(1) + 159 |+assert f"{1}"