Fix can_omit_optional_parentheses for expressions with a right most fstring (#9124)

This commit is contained in:
Micha Reiser 2023-12-14 13:58:17 +09:00 committed by GitHub
parent b8fc006e52
commit 7256b882b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 17 deletions

View file

@ -319,6 +319,18 @@ expected_content = (
)
)
# Skip FString content when determining whether to omit optional parentheses or not.0
# The below expression should be parenthesized because it ends with an fstring and starts with a name.
# (Call expressions at the beginning don't count as parenthesized because they don't start with parens).
assert (
format.format_event(spec)
== f'Event("_remove_cookie", {{key:`testkey`,options:{json.dumps(options)}}})'
)
# Avoid parentheses for this example because it starts with a tuple expression.
assert (
(spec, format)
== f'Event("_remove_cookie", {{key:`testkey`,options:{json.dumps(options)}}})'
)
rowuses = [(1 << j) | # column ordinal
(1 << (n + i-j + n-1)) | # NW-SE ordinal