Slice source code instead of generating it for EM fixes by dhruvmanila · Pull Request #7746 · astral-sh/ruff (original) (raw)

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,

f"""normal {"another"} normal"""

Test Plan

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

fixes: #6988
fixes: #7736