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:
Shantanu 2023-11-06 16:58:43 -08:00 committed by GitHub
parent e808e61db8
commit ecbd9e8cf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 2 deletions

View File

@ -13,6 +13,9 @@
- 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
- Multiline dictionaries and lists that are the sole argument to a function are now

View File

@ -529,7 +529,7 @@ def is_docstring(leaf: Leaf) -> bool:
return False
prefix = get_string_prefix(leaf.value)
if "b" in prefix or "B" in prefix:
if set(prefix).intersection("bBfF"):
return False
if prev_siblings_are(

View File

@ -58,7 +58,8 @@ def docstring_almost_at_line_limit():
def docstring_almost_at_line_limit_with_prefix():
f"""long docstring................................................................"""
f"""long docstring................................................................
"""
def mulitline_docstring_almost_at_line_limit():

View 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)}"""