Separate StringNormalizer
from StringPart
#9954
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR is a small refactor to extract out the logic for normalizing string in the formatter from the
StringPart
struct. It also separates the quote selection into a separate method on the newStringNormalizer
. Both of these will help in the f-string formatting to useStringPart
andchoose_quotes
irrespective of normalization.The reason for having separate quote selection and normalization step is so that the f-string formatting can perform quote selection on its own.
Unlike string and byte literals, the f-string formatting would require that the normalization happens only for the literal elements of it i.e., the "foo" and "bar" in
f"foo {x + y} bar"
. This will automatically be handled by the already separatenormalize_string
function.Another use-case in the f-string formatting is to extract out the relevant information from the
StringPart
like quotes and prefix which is to be passed as context while formatting each element of an f-string.Test Plan
Ensure that clippy is happy and all tests pass.