mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-04 01:36:46 +00:00
Insert newline between docstring and following own line comment (#8216)
**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
This commit is contained in:
parent
cf74debf42
commit
b6c4074836
5 changed files with 275 additions and 7 deletions
|
|
@ -225,8 +225,11 @@ d={'a':1,
|
|||
# fmt: on
|
||||
goes + here,
|
||||
andhere,
|
||||
@@ -122,8 +123,10 @@
|
||||
@@ -120,10 +121,13 @@
|
||||
|
||||
The comments between will be formatted. This is a known limitation.
|
||||
"""
|
||||
+
|
||||
# fmt: off
|
||||
|
||||
- # hey, that won't work
|
||||
|
|
@ -237,7 +240,7 @@ d={'a':1,
|
|||
# fmt: on
|
||||
pass
|
||||
|
||||
@@ -138,7 +141,7 @@
|
||||
@@ -138,7 +142,7 @@
|
||||
now . considers . multiple . fmt . directives . within . one . prefix
|
||||
# fmt: on
|
||||
# fmt: off
|
||||
|
|
@ -246,7 +249,7 @@ d={'a':1,
|
|||
# fmt: on
|
||||
|
||||
|
||||
@@ -178,14 +181,18 @@
|
||||
@@ -178,14 +182,18 @@
|
||||
$
|
||||
""",
|
||||
# fmt: off
|
||||
|
|
@ -395,6 +398,7 @@ def off_and_on_without_data():
|
|||
|
||||
The comments between will be formatted. This is a known limitation.
|
||||
"""
|
||||
|
||||
# fmt: off
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -103,6 +103,45 @@ class ByteDocstring:
|
|||
b""" has leading whitespace"""
|
||||
first_statement = 1
|
||||
|
||||
class CommentAfterDocstring1:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring2:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring3:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring4:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring5:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
|
||||
class TabbedIndent:
|
||||
def tabbed_indent(self):
|
||||
"""check for correct tabbed formatting
|
||||
|
|
@ -222,6 +261,46 @@ class ByteDocstring:
|
|||
first_statement = 1
|
||||
|
||||
|
||||
class CommentAfterDocstring1:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring2:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring3:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring4:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring5:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
|
||||
class TabbedIndent:
|
||||
def tabbed_indent(self):
|
||||
"""check for correct tabbed formatting
|
||||
|
|
@ -341,6 +420,46 @@ class ByteDocstring:
|
|||
first_statement = 1
|
||||
|
||||
|
||||
class CommentAfterDocstring1:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring2:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring3:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring4:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring5:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
|
||||
class TabbedIndent:
|
||||
def tabbed_indent(self):
|
||||
"""check for correct tabbed formatting
|
||||
|
|
@ -460,6 +579,46 @@ class ByteDocstring:
|
|||
first_statement = 1
|
||||
|
||||
|
||||
class CommentAfterDocstring1:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring2:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring3:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring4:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring5:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
|
||||
class TabbedIndent:
|
||||
def tabbed_indent(self):
|
||||
"""check for correct tabbed formatting
|
||||
|
|
@ -579,6 +738,46 @@ class ByteDocstring:
|
|||
first_statement = 1
|
||||
|
||||
|
||||
class CommentAfterDocstring1:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring2:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring3:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring4:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class CommentAfterDocstring5:
|
||||
"""Browse module classes and functions in IDLE."""
|
||||
|
||||
# This class is also the base class for pathbrowser.PathBrowser.
|
||||
|
||||
|
||||
class TabbedIndent:
|
||||
def tabbed_indent(self):
|
||||
"""check for correct tabbed formatting
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue