Skip to content
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 EM102 cause autofix error #6988

Closed
qarmin opened this issue Aug 29, 2023 · 0 comments · Fixed by #7746
Closed

Rules EM102 cause autofix error #6988

qarmin opened this issue Aug 29, 2023 · 0 comments · Fixed by #7746
Labels
bug Something isn't working fuzzer Surfaced via fuzzing.

Comments

@qarmin
Copy link

qarmin commented Aug 29, 2023

Ruff 0.0.286 (latest changes from main branch)

ruff  *.py --select EM102 --no-cache --fix

file content:

class Dependency:
    def validate(self) -> bool:
                raise ValueError(f"""Must provide a value for argument '{self.argument}' if {self.mode.__name__} of: {", ".join(f"'{arg}'" for arg in self.arguments)} are truthy.""")

error:

error: Autofix introduced a syntax error. Reverting all changes.

This indicates a bug in `ruff`. If you could open an issue at:

    https://github.com/astral-sh/ruff/issues/new?title=%5BAutofix%20error%5D

...quoting the contents of `iohandler8090.py`, the rule codes EM102, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

iohandler8090.py:1:1: D100 Missing docstring in public module
iohandler8090.py:1:1: CPY001 Missing copyright notice at top of file
iohandler8090.py:1:7: D101 Missing docstring in public class
iohandler8090.py:2:9: D102 Missing docstring in public method
iohandler8090.py:2:18: ANN101 Missing type annotation for `self` in method
iohandler8090.py:3:1: E117 Over-indented
iohandler8090.py:3:23: TRY003 Avoid specifying long messages outside the exception class
iohandler8090.py:3:34: EM102 Exception must not use an f-string literal, assign to variable first
iohandler8090.py:3:89: E501 Line too long (182 > 88 characters)

iohandler8090.py.zip

@charliermarsh charliermarsh added bug Something isn't working fuzzer Surfaced via fuzzing. labels Aug 30, 2023
dhruvmanila added a commit that referenced this issue Nov 9, 2023
## Summary

This PR fixes the bug where the generated fix for `EM*` rules would
replace a
triple-quoted (f-)string with a single-quoted (f-)string. This changes
the
semantic of the string in case it contains a single-quoted string
literal. This
is especially evident with f-strings where the expression could contain
another
string within it. For example,

```python
f"""normal {"another"} normal"""
```

## Test Plan

Add test case for triple-quoted string and update the snapshots.

fixes: #6988
fixes: #7736
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fuzzer Surfaced via fuzzing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants