Update UP032 to support await expressions (#6304)

<!--
Thank you for contributing to Ruff! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->

In Python >= 3.7, `await` can be included in f-strings. 

https://bugs.python.org/issue28942

## Test Plan

<!-- How was it tested? -->

Existing tests
This commit is contained in:
Harutaka Kawamura 2023-08-03 23:53:36 +09:00 committed by GitHub
parent b6f0316d55
commit 30c2e9430e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 15 deletions

View file

@ -117,6 +117,15 @@ def e():
assert"{}".format(1)
async def c():
return "{}".format(await 3)
async def c():
return "{}".format(1 + await 3)
###
# Non-errors
###
@ -181,13 +190,6 @@ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
]
)
async def c():
return "{}".format(await 3)
async def c():
return "{}".format(1 + await 3)
(
"{a}"
"{1 + 2}"

View file

@ -130,10 +130,7 @@ impl<'a> FormatSummaryValues<'a> {
/// Return `true` if the string contains characters that are forbidden by
/// argument identifiers.
fn contains_invalids(string: &str) -> bool {
string.contains('*')
|| string.contains('\'')
|| string.contains('"')
|| string.contains("await")
string.contains('*') || string.contains('\'') || string.contains('"')
}
enum FormatContext {

View file

@ -877,8 +877,6 @@ UP032_0.py:118:7: UP032 [*] Use f-string instead of `format` call
|
118 | assert"{}".format(1)
| ^^^^^^^^^^^^^^ UP032
119 |
120 | ###
|
= help: Convert to f-string
@ -889,7 +887,43 @@ UP032_0.py:118:7: UP032 [*] Use f-string instead of `format` call
118 |-assert"{}".format(1)
118 |+assert f"{1}"
119 119 |
120 120 | ###
121 121 | # Non-errors
120 120 |
121 121 | async def c():
UP032_0.py:122:12: UP032 [*] Use f-string instead of `format` call
|
121 | async def c():
122 | return "{}".format(await 3)
| ^^^^^^^^^^^^^^^^^^^^ UP032
|
= help: Convert to f-string
Suggested fix
119 119 |
120 120 |
121 121 | async def c():
122 |- return "{}".format(await 3)
122 |+ return f"{await 3}"
123 123 |
124 124 |
125 125 | async def c():
UP032_0.py:126:12: UP032 [*] Use f-string instead of `format` call
|
125 | async def c():
126 | return "{}".format(1 + await 3)
| ^^^^^^^^^^^^^^^^^^^^^^^^ UP032
|
= help: Convert to f-string
Suggested fix
123 123 |
124 124 |
125 125 | async def c():
126 |- return "{}".format(1 + await 3)
126 |+ return f"{1 + await 3}"
127 127 |
128 128 |
129 129 | ###