Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix panic on RUF027 (astral-sh#9990)
## Summary Fixes astral-sh#9895 The cause for this panic came from an offset error in the code. When analyzing a hypothetical f-string, we attempt to re-parse it as an f-string, and use the AST data to determine, among other things, whether the format specifiers are correct. To determine the 'correctness' of a format specifier, we actually have to re-parse the format specifier, and this is where the issue lies. To get the source text for the specifier, we were taking a slice from the original file source text... even though the AST data for the specifier belongs to the standalone parsed f-string expression, meaning that the ranges are going to be way off. In a file with Unicode, this can cause panics if the slice is inside a char boundary. To fix this, we now slice from the temporary source we created earlier to parse the literal as an f-string. ## Test Plan The RUF027 snapshot test was amended to include a string with format specifiers which we _should_ be calling out. This is to ensure we do slice format specifiers from the source text correctly.
- Loading branch information