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

style regression: too long single line docstrings have their quotes moved to a new line. #3320

Closed
onerandomusername opened this issue Oct 10, 2022 · 6 comments · Fixed by #3430
Labels
F: docstrings How we format docstrings F: linebreak How should we split up lines? T: bug Something isn't working

Comments

@onerandomusername
Copy link
Contributor

Describe the bug

Single-line docstrings that are longer than the line length have the final three " moved to a new line.

To Reproduce

For example, take this code:

from typing import Optional

# leaves this the same
def large_image_url(self) -> Optional[str]:
    """Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable.
    """
    pass


# leaves this the same too
def large_image_url(self) -> Optional[str]:
    """
    Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable.
    """
    pass


# depending on the length of the docstring, this one *may* be left as-is
def large_image_url(self) -> Optional[str]:
    """
    Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable."""
    pass


# but this one is modified
def large_image_url(self) -> Optional[str]:
    """Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable."""
    pass

And run it with these arguments:

$ black file.py --preview

We get this format:

from typing import Optional

# leaves this the same
def large_image_url(self) -> Optional[str]:
    """Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable.
    """
    pass


# leaves this the same too
def large_image_url(self) -> Optional[str]:
    """
    Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable.
    """
    pass


# this one is also left as-is
def large_image_url(self) -> Optional[str]:
    """
    Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable.
    """
    pass


# but this one is modified
def large_image_url(self) -> Optional[str]:
    """Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable.
    """
    pass

Expected behavior

Single line docstrings are left alone. I understand what this change is supposed to do, and on already multiline docstrings this wouldn't be an issue (although it would be nice for the docstring formatter to be entirely consistent among all docstrings instead of having different behavior for the line length but i digress).

Environment

  • Black's version: 22.10.0
  • OS and Python version: Python 3.11.0rc2, on linux, but i can recreate with python 3.8 too

Additional Comments

This seems like a regression from #3044

@onerandomusername onerandomusername added the T: bug Something isn't working label Oct 10, 2022
@felix-hilden felix-hilden added the F: docstrings How we format docstrings label Oct 10, 2022
@ichard26 ichard26 added the F: linebreak How should we split up lines? label Oct 10, 2022
@itxasos23
Copy link

itxasos23 commented Oct 12, 2022

Hey! I'd like to contribute to fixing this bug as part of Hacktoberfest.
Hope that's ok!

@felix-hilden
Copy link
Collaborator

Hi! Looking at the changes again, it seems intended.

@itxasos23 Thanks for offering! However, #2885 deals with docstrings and could clash with this change. So I think we'll at least have to discuss a bit. If you'd be willing to try something else, have a look at the ones in good first issue Good for newcomers !

@onerandomusername
Copy link
Contributor Author

onerandomusername commented Oct 17, 2022

Hi! Looking at the changes again, it seems intended.

The biggest problem is this change for single line docstrings is a violation of PEP 257.

  • The closing quotes are on the same line as the opening quotes. This looks better for one-liners.

@itxasos23
Copy link

@felix-hilden Amazing! I see you got that covered on that PR 😄

@onerandomusername
Copy link
Contributor Author

However, #2885 deals with docstrings and could clash with this change.

This pr is in agreement with 2885, as the author of 2885 states:

At the moment, any docstring with only one line of content will be converted to the one-line form.

This is in line with pep 257, and should satisfy this issue as well.

@JelleZijlstra
Copy link
Collaborator

I propose a fix in #3430. cc @idorrington92 as the author of #3044 which introduced this behavior.

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 F: linebreak How should we split up lines? T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants