Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash with f-string docstrings #4019

Merged
merged 3 commits into from Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/black/nodes.py
Expand Up @@ -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 "b" in prefix or "B" in prefix or "f" in prefix or "F" in prefix:
hauntsaninja marked this conversation as resolved.
Show resolved Hide resolved
return False

if prev_siblings_are(
Expand Down
3 changes: 2 additions & 1 deletion tests/data/cases/docstring_preview.py
Expand Up @@ -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():
Expand Down
20 changes: 20 additions & 0 deletions tests/data/cases/f_docstring.py
@@ -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)}"""