parent
e50110353a
commit
5758da6e3c
@ -8,8 +8,8 @@
|
||||
|
||||
### Stable style
|
||||
|
||||
- Fix a crash when whitespace(s) followed a backslash before newline in a docstring
|
||||
(#4008)
|
||||
- Fix crash on formatting bytes strings that look like docstrings (#4003)
|
||||
- Fix crash when whitespace followed a backslash before newline in a docstring (#4008)
|
||||
|
||||
### Preview style
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
from black.cache import CACHE_DIR
|
||||
from black.mode import Mode, Preview
|
||||
from black.strings import has_triple_quotes
|
||||
from black.strings import get_string_prefix, has_triple_quotes
|
||||
from blib2to3 import pygram
|
||||
from blib2to3.pgen2 import token
|
||||
from blib2to3.pytree import NL, Leaf, Node, type_repr
|
||||
@ -525,6 +525,13 @@ def is_arith_like(node: LN) -> bool:
|
||||
|
||||
|
||||
def is_docstring(leaf: Leaf) -> bool:
|
||||
if leaf.type != token.STRING:
|
||||
return False
|
||||
|
||||
prefix = get_string_prefix(leaf.value)
|
||||
if "b" in prefix or "B" in prefix:
|
||||
return False
|
||||
|
||||
if prev_siblings_are(
|
||||
leaf.parent, [None, token.NEWLINE, token.INDENT, syms.simple_stmt]
|
||||
):
|
||||
|
34
tests/data/cases/bytes_docstring.py
Normal file
34
tests/data/cases/bytes_docstring.py
Normal file
@ -0,0 +1,34 @@
|
||||
def bitey():
|
||||
b" not a docstring"
|
||||
|
||||
def bitey2():
|
||||
b' also not a docstring'
|
||||
|
||||
def triple_quoted_bytes():
|
||||
b""" not a docstring"""
|
||||
|
||||
def triple_quoted_bytes2():
|
||||
b''' also not a docstring'''
|
||||
|
||||
def capitalized_bytes():
|
||||
B" NOT A DOCSTRING"
|
||||
|
||||
# output
|
||||
def bitey():
|
||||
b" not a docstring"
|
||||
|
||||
|
||||
def bitey2():
|
||||
b" also not a docstring"
|
||||
|
||||
|
||||
def triple_quoted_bytes():
|
||||
b""" not a docstring"""
|
||||
|
||||
|
||||
def triple_quoted_bytes2():
|
||||
b""" also not a docstring"""
|
||||
|
||||
|
||||
def capitalized_bytes():
|
||||
b" NOT A DOCSTRING"
|
Loading…
Reference in New Issue
Block a user