Single line comment following multiline string is handled incorrectly
- Dominant language
- Python
- Stars
- 14k
- Forks
- 904
- PR merge metrics
- No merged PRs in 30d
Description
Consider the following code (in `test.py`):
```
if True:
'''
Flabbergast
''' # Really!?
pass
```
Calling `yapf --style='{based_on_style: pep8, spaces_before_comment: 1}' test.py` with this code will produce:
```
if True:
'''
Flabbergast
'''
# Really!?
pass
```
This will nicely prefix 1 space before the comment, except this makes the comment fall short of the indentation of the `if`-statement. (Note: I explicitly set the `spaces_before_comment` to 1 in order to highlight the effect, this issue will manifest with any value for this configuration item).
Running yapf on this output again produces the actually expected result as shown in the diff below:
```
--- test2.py (original)
+++ test2.py (reformatted)
@@ -3,5 +3,5 @@
Flabbergast
'''
- # Really!?
+ # Really!?
pass
```
Here the comment is nicely indented with 4 spaces, right in line with the rest of the `if`-block.
I would expect the output of the 2nd run to be produced in the 1st run, which is why I'm raising this issue.
Contributor guide
Assessment
This issue has not been assessed yet.