Skip to content

Commit

Permalink
Regression fix: leave R prefixes capitalization alone
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
ichard26 committed May 30, 2021
1 parent eec44f5 commit ca7a34d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -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_

Expand Down
2 changes: 1 addition & 1 deletion src/black/strings.py
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/data/string_prefixes.py
Expand Up @@ -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


Expand All @@ -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
"""

0 comments on commit ca7a34d

Please sign in to comment.