mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
Add syntax error when conversion flag does not immediately follow exclamation mark (#18706)
Closes #18671 Note that while this has, I believe, always been invalid syntax, it was reported as a different syntax error until Python 3.12: Python 3.11: ```pycon >>> x = 1 >>> f"{x! s}" File "<stdin>", line 1 f"{x! s}" ^ SyntaxError: f-string: invalid conversion character: expected 's', 'r', or 'a' ``` Python 3.12: ```pycon >>> x = 1 >>> f"{x! s}" File "<stdin>", line 1 f"{x! s}" ^^^ SyntaxError: f-string: conversion type must come right after the exclamanation mark ```
This commit is contained in:
parent
a842899862
commit
c5b58187da
8 changed files with 219 additions and 38 deletions
|
@ -267,17 +267,13 @@ aaaaaaaaaaa = f"""asaaaaaaaaaaaaaaaa {
|
|||
|
||||
# Conversion flags
|
||||
#
|
||||
# This is not a valid Python code because of the additional whitespace between the `!`
|
||||
# and conversion type. But, our parser isn't strict about this. This should probably be
|
||||
# removed once we have a strict parser.
|
||||
x = f"aaaaaaaaa { x ! r }"
|
||||
|
||||
# Even in the case of debug expressions, we only need to preserve the whitespace within
|
||||
# the expression part of the replacement field.
|
||||
x = f"aaaaaaaaa { x = ! r }"
|
||||
x = f"aaaaaaaaa { x = !r }"
|
||||
|
||||
# Combine conversion flags with format specifiers
|
||||
x = f"{x = ! s
|
||||
x = f"{x = !s
|
||||
:>0
|
||||
|
||||
}"
|
||||
|
|
|
@ -265,17 +265,13 @@ aaaaaaaaaaa = t"""asaaaaaaaaaaaaaaaa {
|
|||
|
||||
# Conversion flags
|
||||
#
|
||||
# This is not a valid Python code because of the additional whitespace between the `!`
|
||||
# and conversion type. But, our parser isn't strict about this. This should probably be
|
||||
# removed once we have a strict parser.
|
||||
x = t"aaaaaaaaa { x ! r }"
|
||||
|
||||
# Even in the case of debug expressions, we only need to preserve the whitespace within
|
||||
# the expression part of the replacement field.
|
||||
x = t"aaaaaaaaa { x = ! r }"
|
||||
x = t"aaaaaaaaa { x = !r }"
|
||||
|
||||
# Combine conversion flags with format specifiers
|
||||
x = t"{x = ! s
|
||||
x = t"{x = !s
|
||||
:>0
|
||||
|
||||
}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue