You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue Description:
Ruff does not seem to detect syntax errors related to unmatched quotes within f-strings. This issue is not flagged either during static analysis with ruff check or formatting with ruff format. However, similar tools like flake8 and black, as well as IDEs like PyCharm, are able to identify and report this syntax error.
Steps to Reproduce:
Create a Python file (temp.py) with the following content:
a= {"number": 1}
b=f"number {a["number"]}"# Note the unmatched quotes inside the f-stringprint(b)
Run ruff check temp.py and observe that there is no output, indicating no issues were detected.
Run python3 -m flake8 temp.py to compare, and the output is: temp.py:2:18: E999 SyntaxError: f-string: unmatched '['
Similarly, running python3 -m black temp.py results in a parsing error: error: cannot format temp.py: Cannot parse: 2:17: b = f"number {a["number"]}" Oh no! 💥 💔 💥 1 file failed to reformat.
Attempting to format the file with ruff format temp.py merely returns 1 file left unchanged, without addressing or flagging the syntax issue.
The problem can be detected in Pycharm as well:
The text was updated successfully, but these errors were encountered:
Ruff accepts the above syntax because it is valid in Python 3.12 (see announcement). Black doesn't support that syntax yet and so must flake8. I'm not sure what Pycharm does. It either detects that you target an older Python version in your project and, because of it, parses the f-string according to the "old" rules OR you have to update pycharm to a more recent version. We have plans to eventually warn for unsupported syntax depending on your requires-python setting but that's something we don't support today.
Thank you for your prompt response and clarification regarding the syntax acceptance in Ruff due to Python 3.12's new features. I understand that Ruff aligns with the latest Python standards, which is indeed commendable. However, my projects are currently on Python 3.9 and Python 3.11, and it's crucial for me to catch syntax errors that are incompatible with these versions.
Given that Python 3.12 introduces changes not backward-compatible with earlier versions, it would be highly beneficial if Ruff could provide version-specific syntax validation. This feature would greatly enhance the tool's utility in environments where upgrading to the latest Python version isn't immediately feasible.
Thank you for considering this enhancement. I believe it would make Ruff an even more indispensable tool for Python developers navigating the complexities of version-specific syntax rules.
Ruff Version: 0.2.2
Issue Description:
Ruff does not seem to detect syntax errors related to unmatched quotes within f-strings. This issue is not flagged either during static analysis with
ruff check
or formatting withruff format
. However, similar tools likeflake8
andblack
, as well as IDEs like PyCharm, are able to identify and report this syntax error.Steps to Reproduce:
temp.py
) with the following content:Run
ruff check temp.py
and observe that there is no output, indicating no issues were detected.Run
python3 -m flake8 temp.py
to compare, and the output is:temp.py:2:18: E999 SyntaxError: f-string: unmatched '['
Similarly, running
python3 -m black temp.py
results in a parsing error:error: cannot format temp.py: Cannot parse: 2:17: b = f"number {a["number"]}" Oh no! 💥 💔 💥 1 file failed to reformat.
Attempting to format the file with
ruff format temp.py
merely returns1 file left unchanged
, without addressing or flagging the syntax issue.The problem can be detected in Pycharm as well:
The text was updated successfully, but these errors were encountered: