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

Black removing extra spaces in docstrings. Breaking markdown formatting #3306

Open
cazador481 opened this issue Oct 3, 2022 · 3 comments
Open
Labels
F: docstrings How we format docstrings T: bug Something isn't working

Comments

@cazador481
Copy link

When a docstring is formatted using markdown, an extra space at the end means that the next line is not to be wrapped. (pydoc3 uses markdown). Unfortunately, black removes the extra space, which causes markdown renders to not do what they are supposed to.

Example code that gets miss rendered. Note: I am using a _ to denote a space at the end of the line.
Original

def boo():
    """Halloween.

    This is not supposed to be wrapped._ 
    New text
    """

After running black:

def boo():
    """Halloween.

    This is not supposed to be wrapped.
    New text
    """

Expected:

def boo():
    """Halloween.

    This is not supposed to be wrapped._
    New text
    """

Environment

  • Black's version: 22.8.0
  • OS and Python version: linux: 3.9.13
@cazador481 cazador481 added the T: bug Something isn't working label Oct 3, 2022
@cazador481 cazador481 changed the title Black removing extra lines in docstrings. Breaking markdown formatting Black removing extra spaces in docstrings. Breaking markdown formatting Oct 3, 2022
@JelleZijlstra JelleZijlstra added the F: docstrings How we format docstrings label Oct 3, 2022
@felix-hilden
Copy link
Collaborator

Right, this is definitely intentional, tracing all the way back to #1053. I'd say it's desirable in most cases, but not sure about this one.

@pawamoy
Copy link

pawamoy commented Oct 17, 2022

Unfortunately that's the only way to break a line in common Markdown (two trailing spaces), apart from using <br> 😕

Is Black assuming a specific markup for docstrings?

@pawamoy
Copy link

pawamoy commented Nov 27, 2022

In fact CommonMark says that we can use a backslash instead of trailing spaces.

For those using Python-Markdown / MkDocs, it has been asked before: Python-Markdown/markdown#1157.
Suggested solution: use the pymdownx.escapeall extension, with the hardbreak option enabled:

markdown_extensions:
- pymdownx.escapeall:
    hardbreak: yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: docstrings How we format docstrings T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants