Skip to content

Commit

Permalink
string prefixes: don't normalise capital R-strings (#1271)
Browse files Browse the repository at this point in the history
Resolves #1244

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
  • Loading branch information
hauntsaninja and ambv committed Mar 3, 2020
1 parent bbe5ae7 commit 6d8b901
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion black.py
Expand Up @@ -2842,7 +2842,7 @@ def normalize_string_prefix(leaf: Leaf, remove_u_prefix: bool = False) -> None:
match = re.match(r"^([furbFURB]*)(.*)$", leaf.value, re.DOTALL)
assert match is not None, f"failed to match string {leaf.value!r}"
orig_prefix = match.group(1)
new_prefix = orig_prefix.lower()
new_prefix = orig_prefix.replace("F", "f").replace("B", "b").replace("U", "u")
if remove_u_prefix:
new_prefix = new_prefix.replace("u", "")
leaf.value = f"{new_prefix}{match.group(2)}"
Expand Down
6 changes: 5 additions & 1 deletion tests/data/string_prefixes.py
Expand Up @@ -3,12 +3,16 @@
name = R"Łukasz"
F"hello {name}"
B"hello"
r"hello"
fR"hello"

# output


#!/usr/bin/env python3.6

name = r"Łukasz"
name = R"Łukasz"
f"hello {name}"
b"hello"
r"hello"
fR"hello"

0 comments on commit 6d8b901

Please sign in to comment.