Missing blank line between docstrings of class attributes and first method?
- Dominant language
- Python
- Stars
- 14k
- Forks
- 904
- PR merge metrics
- No merged PRs in 30d
Description
First of all, thanks for the great tool. I can usually find a knob or other hint that will convince yapf to _do the right thing_ but I've hit a case that I don't completely understand. Consider the following class:
```python
class SomeClass:
"""Does something useful."""
logger: logging.Logger
"""A handler specific logger with an appropriate name."""
def __init__(self):
...
```
When I run this through yapf using the PEP8 style, the blank line between the docstring for `logger` and `__init__` is removed. The result is:
```python
class SomeClass:
"""Does something useful."""
logger: logging.Logger
"""A handler specific logger with an appropriate name."""
def __init__(self):
...
```
I've experimented with a number of different cases like omitting the class docstring and using multiline docstrings. The only thing that is interesting is that this only occurs with the first method in the class definition. Blank lines are inserted correctly for class attributes defined between methods ... just not before the first method.
The following degenerate case shows that blank lines are inserted around the `why_here` attribute.
```python
class SomeClass:
logger: logging.Logger
"""A handler specific logger with an appropriate name."""
def handle_request(self, request): pass
why_here: typing.Any
"""TODO - figure out why this works."""
def __init__(self): pass
```
```python
class SomeClass:
logger: logging.Logger
"""A handler specific logger with an appropriate name."""
def handle_request(self, request):
pass
why_here: typing.Any
"""TODO - figure out why this works."""
def __init__(self):
pass
```
Contributor guide
Assessment
This issue has not been assessed yet.