Allow Locator#slice to take Ranged (#6922)

## Summary

As a small quality-of-life improvement, the locator can now slice like
`locator.slice(stmt)` instead of requiring
`locator.slice(stmt.range())`.

## Test Plan

`cargo test`
This commit is contained in:
Charlie Marsh 2023-08-28 11:08:39 -04:00 committed by GitHub
parent 58f5f27dc3
commit aea7500c1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 89 additions and 96 deletions

View file

@ -788,12 +788,12 @@ fn format_docstring(string_part: &FormatStringPart, f: &mut PyFormatter) -> Form
let locator = f.context().locator();
// Black doesn't change the indentation of docstrings that contain an escaped newline
if locator.slice(string_part.range()).contains("\\\n") {
if locator.slice(string_part).contains("\\\n") {
return string_part.fmt(f);
}
let (normalized, _) = normalize_string(
locator.slice(string_part.range()),
locator.slice(string_part),
string_part.preferred_quotes,
string_part.is_raw_string,
);