astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
33.27k stars 1.11k forks source link

Q003 autofix for triple nested quotes is not valid python code #8739

Closed dragon-dxw closed 1 year ago

dragon-dxw commented 1 year ago

Version: 0.1.5 input: msg = f"Document \"{context['document'].name}\" does not have a PDF." error [no args, invoked by precommit]: judgments/views/document_full_text.py:38:19: Q003 [*] Change outer quotes to avoid escaping inner quotes autofix via --fix [via precommit] msg = f'Document "{context['document'].name}" does not have a PDF.' which is not valid python

ruff config: https://github.com/nationalarchives/ds-caselaw-editor-ui/blob/chore/test-factory-improvements/pyproject.toml

sciyoshi commented 1 year ago

@dragon-dxw the fixed version is in fact valid syntax in Python 3.12. If you set the target Python version to 3.11 or lower in your configuration using target-version, this should no longer be marked as an error. See https://github.com/astral-sh/ruff/pull/7588

charliermarsh commented 1 year ago

Yeah, in my testing this seems to be correctly detected based on the Python version. Do you mind testing if your Python version is set to Python 3.12? Happy to revisit if we're able to reproduce with a lower target-version.