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

Insert newline after docstring even when there are comments #7948

Closed
konstin opened this issue Oct 13, 2023 · 3 comments · Fixed by #8216
Closed

Insert newline after docstring even when there are comments #7948

konstin opened this issue Oct 13, 2023 · 3 comments · Fixed by #8216
Assignees
Labels
bug Something isn't working formatter Related to the formatter

Comments

@konstin
Copy link
Member

konstin commented Oct 13, 2023

Ours:

class ModuleBrowser:
    """Browse module classes and functions in IDLE."""
    # This class is also the base class for pathbrowser.PathBrowser.

    def __init__(self, master, path, *, _htest=False, _utest=False):
        pass

Black:

class ModuleBrowser:
    """Browse module classes and functions in IDLE."""

    # This class is also the base class for pathbrowser.PathBrowser.

    def __init__(self, master, path, *, _htest=False, _utest=False):
        pass

We should also insert the empty line after the docstring even if there is comment

@konstin konstin added bug Something isn't working formatter Related to the formatter labels Oct 13, 2023
@charliermarsh
Copy link
Member

This might be intentional (though whether it’s good is debatable) — I believe we intentionally don’t insert a newline like that if it immediately follows an import, unlike Black.

@charliermarsh
Copy link
Member

What if there’s no empty line between the comment and the function definition?

@konstin
Copy link
Member Author

konstin commented Oct 13, 2023

What if there’s no empty line between the comment and the function definition?

In that case both we do the same thing as black, one empty line between docstring and the own line comment

@MichaReiser MichaReiser added this to the Formatter: Stable milestone Oct 16, 2023
@konstin konstin self-assigned this Oct 20, 2023
konstin added a commit that referenced this issue Oct 30, 2023
**Summary** Previously, own line comment following after a docstring
followed by newline(s) before the first content statement were treated
as trailing on the docstring and we didn't insert a newline after the
docstring as black would.

Before:
```python
class ModuleBrowser:
    """Browse module classes and functions in IDLE."""
    # This class is also the base class for pathbrowser.PathBrowser.

    def __init__(self, master, path, *, _htest=False, _utest=False):
        pass
```
After:
```python
class ModuleBrowser:
    """Browse module classes and functions in IDLE."""

    # This class is also the base class for pathbrowser.PathBrowser.

    def __init__(self, master, path, *, _htest=False, _utest=False):
        pass
```

I'm not entirely happy about hijacking
`handle_own_line_comment_between_statements`, but i don't know a better
spot to put it.

Fixes #7948

**Test Plan** Fixtures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatter Related to the formatter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants