From ca7a34db16d65afd1fbd43848bab475d9b88d233 Mon Sep 17 00:00:00 2001 From: Richard Si <63936253+ichard26@users.noreply.github.com> Date: Sun, 30 May 2021 16:16:19 -0400 Subject: [PATCH] Regression fix: leave R prefixes capitalization alone `black.strings.get_string_prefix` used to lowercase the extracted prefix before returning it. This is wrong because 1) it ignores the fact we should leave R prefixes alone because of MagicPython, and 2) there is dedicated prefix casing handling code that fixes issue 1. `.lower` is too naive. This was originally fixed in 20.8b0, but was reintroduced since 21.4b0. --- CHANGES.md | 1 + src/black/strings.py | 2 +- tests/data/string_prefixes.py | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 63c7a2cf30d..562b28d8039 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ - Restored compatibility with Click 8.0 on Python 3.6 when LANG=C used (#2227) - Add extra uvloop install + import support if in python env (#2258) - Fix --experimental-string-processing crash when matching parens are not found (#2283) +- Fix regression where `R` prefixes would be lowercased for docstrings (#2285) ### _Blackd_ diff --git a/src/black/strings.py b/src/black/strings.py index 5b443ddebc9..80f588f5119 100644 --- a/src/black/strings.py +++ b/src/black/strings.py @@ -87,7 +87,7 @@ def get_string_prefix(string: str) -> str: prefix = "" prefix_idx = 0 while string[prefix_idx] in STRING_PREFIX_CHARS: - prefix += string[prefix_idx].lower() + prefix += string[prefix_idx] prefix_idx += 1 return prefix diff --git a/tests/data/string_prefixes.py b/tests/data/string_prefixes.py index 0ca3686a2b6..9ddc2b540fc 100644 --- a/tests/data/string_prefixes.py +++ b/tests/data/string_prefixes.py @@ -6,6 +6,17 @@ r"hello" fR"hello" + +def docstring_singleline(): + R"""2020 was one hell of a year. The good news is that we were able to""" + + +def docstring_multiline(): + R""" + clear out all of the issues opened in that time :p + """ + + # output @@ -16,3 +27,13 @@ b"hello" r"hello" fR"hello" + + +def docstring_singleline(): + R"""2020 was one hell of a year. The good news is that we were able to""" + + +def docstring_multiline(): + R""" + clear out all of the issues opened in that time :p + """