ruff
6f9c128d - Separate `StringNormalizer` from `StringPart` (#9954)

Comment changes are shownComment changes are hidden
Commit
1 year ago
Separate `StringNormalizer` from `StringPart` (#9954) ## 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 new `StringNormalizer`. Both of these will help in the f-string formatting to use `StringPart` and `choose_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 separate `normalize_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.
Author
Parents
  • crates/ruff_python_formatter/src
    • other
      • File
        bytes_literal.rs
      • File
        f_string.rs
      • File
        string_literal.rs
    • string
      • File
        mod.rs