Fix crash with f-string docstrings (#4019)
Python does not consider f-strings to be docstrings, so we probably shouldn't be formatting them as such Fixes #4018 Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
e808e61db8
commit
ecbd9e8cf7
@ -13,6 +13,9 @@
|
|||||||
|
|
||||||
- Fix crash on formatting code like `await (a ** b)` (#3994)
|
- Fix crash on formatting code like `await (a ** b)` (#3994)
|
||||||
|
|
||||||
|
- No longer treat leading f-strings as docstrings. This matches Python's behaviour and
|
||||||
|
fixes a crash (#4019)
|
||||||
|
|
||||||
### Preview style
|
### Preview style
|
||||||
|
|
||||||
- Multiline dictionaries and lists that are the sole argument to a function are now
|
- Multiline dictionaries and lists that are the sole argument to a function are now
|
||||||
|
@ -529,7 +529,7 @@ def is_docstring(leaf: Leaf) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
prefix = get_string_prefix(leaf.value)
|
prefix = get_string_prefix(leaf.value)
|
||||||
if "b" in prefix or "B" in prefix:
|
if set(prefix).intersection("bBfF"):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if prev_siblings_are(
|
if prev_siblings_are(
|
||||||
|
@ -58,7 +58,8 @@ def docstring_almost_at_line_limit():
|
|||||||
|
|
||||||
|
|
||||||
def docstring_almost_at_line_limit_with_prefix():
|
def docstring_almost_at_line_limit_with_prefix():
|
||||||
f"""long docstring................................................................"""
|
f"""long docstring................................................................
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def mulitline_docstring_almost_at_line_limit():
|
def mulitline_docstring_almost_at_line_limit():
|
||||||
|
20
tests/data/cases/f_docstring.py
Normal file
20
tests/data/cases/f_docstring.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
def foo(e):
|
||||||
|
f""" {'.'.join(e)}"""
|
||||||
|
|
||||||
|
def bar(e):
|
||||||
|
f"{'.'.join(e)}"
|
||||||
|
|
||||||
|
def baz(e):
|
||||||
|
F""" {'.'.join(e)}"""
|
||||||
|
|
||||||
|
# output
|
||||||
|
def foo(e):
|
||||||
|
f""" {'.'.join(e)}"""
|
||||||
|
|
||||||
|
|
||||||
|
def bar(e):
|
||||||
|
f"{'.'.join(e)}"
|
||||||
|
|
||||||
|
|
||||||
|
def baz(e):
|
||||||
|
f""" {'.'.join(e)}"""
|
Loading…
Reference in New Issue
Block a user