Disallow newlines in format specifiers of single quoted f- or t-strings (#18708)

This commit is contained in:
Micha Reiser 2025-06-18 14:56:15 +02:00 committed by GitHub
parent 23261a38a0
commit 1188ffccc4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 521 additions and 513 deletions

View file

@ -74,8 +74,7 @@ x = f"a{2+2:=^{foo(x+y**2):something else}one more}b"
f'{(abc:=10)}'
f"This is a really long string, but just make sure that you reflow fstrings {
2+2:d
}"
2+2:d}"
f"This is a really long string, but just make sure that you reflow fstrings correctly {2+2:d}"
f"{2+2=}"

View file

@ -278,16 +278,7 @@ x = f"aaaaaaaaa { x = !r }"
# Combine conversion flags with format specifiers
x = f"{x = !s
:>0
}"
# This is interesting. There can be a comment after the format specifier but only if it's
# on it's own line. Refer to https://github.com/astral-sh/ruff/pull/7787 for more details.
# We'll format is as trailing comments.
x = f"{x !s
:>0
# comment 21
}"
:>0}"
x = f"{
x!s:>{
@ -295,6 +286,13 @@ x = f"{
# comment 21-2
}}"
f"{1
# comment 21-3
:}"
f"{1 # comment 21-4
:} a"
x = f"""
{ # comment 22
@ -311,14 +309,14 @@ x = f"""{"foo " + # comment 24
"""
# Mix of various features.
f"{ # comment 26
f"""{ # comment 26
foo # after foo
:>{
x # after x
}
# comment 27
# comment 28
} woah {x}"
} woah {x}"""
f"""{foo
@ -332,8 +330,7 @@ f"""{foo
f"{
# comment 31
foo
:>
}"
:>}"
# Assignment statement
@ -487,13 +484,11 @@ aaaaa[aaaaaaaaaaa] = (
# This is not a multiline f-string even though it has a newline after the format specifier.
aaaaaaaaaaaaaaaaaa = f"testeeeeeeeeeeeeeeeeeeeeeeeee{
a:.3f
}moreeeeeeeeeeeeeeeeeetest" # comment
a:.3f}moreeeeeeeeeeeeeeeeeetest" # comment
aaaaaaaaaaaaaaaaaa = (
f"testeeeeeeeeeeeeeeeeeeeeeeeee{
a:.3f
}moreeeeeeeeeeeeeeeeeetest" # comment
a:.3f}moreeeeeeeeeeeeeeeeeetest" # comment
)
# The newline is only considered when it's a tripled-quoted f-string.

View file

@ -274,16 +274,7 @@ x = t"aaaaaaaaa { x = !r }"
# Combine conversion flags with format specifiers
x = t"{x = !s
:>0
}"
# This is interesting. There can be a comment after the format specifier but only if it's
# on it's own line. Refer to https://github.com/astral-sh/ruff/pull/7787 for more details.
# We'll format is as trailing comments.
x = t"{x !s
:>0
# comment 21
}"
:>0}"
x = f"{
x!s:>{
@ -291,6 +282,13 @@ x = f"{
# comment 21-2
}}"
f"{1
# comment 21-3
:}"
f"{1 # comment 21-4
:} a"
x = t"""
{ # comment 22
x = :.0{y # comment 23
@ -306,14 +304,14 @@ x = t"""{"foo " + # comment 24
"""
# Mix of various features.
t"{ # comment 26
t"""{ # comment 26
foo # after foo
:>{
x # after x
}
# comment 27
# comment 28
} woah {x}"
} woah {x}"""
# Assignment statement
@ -467,13 +465,11 @@ aaaaa[aaaaaaaaaaa] = (
# This is not a multiline t-string even though it has a newline after the format specifier.
aaaaaaaaaaaaaaaaaa = t"testeeeeeeeeeeeeeeeeeeeeeeeee{
a:.3f
}moreeeeeeeeeeeeeeeeeetest" # comment
a:.3f}moreeeeeeeeeeeeeeeeeetest" # comment
aaaaaaaaaaaaaaaaaa = (
t"testeeeeeeeeeeeeeeeeeeeeeeeee{
a:.3f
}moreeeeeeeeeeeeeeeeeetest" # comment
a:.3f}moreeeeeeeeeeeeeeeeeetest" # comment
)
# The newline is only considered when it's a tripled-quoted t-string.