-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rules Q002,PTH116 causes autofix error #6785
Comments
Since the beginning gets converted to |
The underlying classes and concepts handling this quote-fixing mechanism used for inline/multiline strings as well as docstrings look interesting. I give it a shot. |
Hey @zanieb, in case you are interested in the fix, I'd highly appreciate a review. I got in the habit of tagging Charlie whenever I had PR's to review, but do not want to put the pressure of reviewing on him all the time as he has probably a lot of things to do. You are a maintainer as well, aren't you? Thanks! |
I'll try to take a look this week. |
## Summary In issue #6785 it is reported that a docstring in the form of `''"assert" ' SAM macro definitions '''` is autocorrected to `"""assert" ' SAM macro definitions '''` (note the triple quotes one only one side), which breaks the python program due `undetermined string lateral`. * `Q002`: Not only would docstrings in the form of `''"assert" ' SAM macro definitions '''` (single quotes) be autofixed wrongly, but also e.g. `""'assert' ' SAM macro definitions '''` (double quotes). The bug is present for docstrings in all scopes (e.g. module docstrings, class docstrings, function docstrings) * `Q000`: The autofix error is not only present for `Q002` (docstrings), but also for inline strings (`Q000`). Therefore `s = ''"assert" ' SAM macro definitions '''` will also be wrongly autofixed. Note that situation in which the first string is non-empty can be fixed, e.g. `'123'"assert" ' SAM macro definitions '''` -> `"123""assert" ' SAM macro definitions '''` is valid. ## What * Change FixAvailability of `Q000` `Q002` to `Sometimes` * Changed both rules such that docstrings/inline strings that cannot be fixed are still reported as bad quotes via diagnostics, but no fix is provided ## Test Plan * For `Q000`: Add docstrings in different scopes that (partially) would have been autofixed wrongly * For `Q002`: Add inline strings that (partially) would have been autofixed wrongly Closes #6785
Ruff 0.0.285 (latest changes from main branch)
file content:
error:
869198225PY_FILE_TEST_7954205181857005371.py.zip
The text was updated successfully, but these errors were encountered: