-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Slice source code instead of generating it for EM
fixes
#7746
Conversation
Current dependencies on/for this PR: This stack of pull requests is managed by Graphite. |
crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs
Outdated
Show resolved
Hide resolved
This comment was marked as outdated.
This comment was marked as outdated.
b861379
to
346ee92
Compare
346ee92
to
a61a608
Compare
|
ea28834
to
451acea
Compare
format!( | ||
"msg = ({line_ending}{stmt_indentation}{indentation}{}{line_ending}{stmt_indentation}){line_ending}{stmt_indentation}", | ||
locator.slice(exc_arg.range()), | ||
line_ending = stylist.line_ending().as_str(), | ||
indentation = stylist.indentation().as_str(), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this too much? 😅
We can just keep a simple format!("msg = ({}){}{}")
instead.
74 74 | | ||
75 75 | def f_multi_line_string2(): | ||
76 |- raise RuntimeError( | ||
76 |+ msg = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So these probably should be omitted, right? But we don't have a general way to know if the inner expression needs parentheses, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct.
451acea
to
8f8a6c0
Compare
8f8a6c0
to
314c9ea
Compare
Summary
This PR fixes the bug where the generated fix for
EM*
rules would replace atriple-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,
f"""normal {"another"} normal"""
Test Plan
Add test case for triple-quoted string and update the snapshots.
fixes: #6988
fixes: #7736