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

Possible fix for issue with indentation and fmt: skip #2281

Merged
merged 5 commits into from Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -4,6 +4,7 @@

### _Black_

- Fix failure caused by `fmt: skip` and indentation (#2281)
- Correct max string length calculation when there are string operators (#2292)

## 21.5b2
Expand Down
5 changes: 4 additions & 1 deletion src/black/comments.py
Expand Up @@ -159,7 +159,10 @@ def convert_one_fmt_off_pair(node: Node) -> bool:
first = ignored_nodes[0] # Can be a container node with the `leaf`.
parent = first.parent
prefix = first.prefix
first.prefix = prefix[comment.consumed :]
if comment.value in FMT_OFF:
first.prefix = prefix[comment.consumed :]
if comment.value in FMT_SKIP:
first.prefix = ""
hidden_value = "".join(str(n) for n in ignored_nodes)
if comment.value in FMT_OFF:
hidden_value = comment.value + "\n" + hidden_value
Expand Down
13 changes: 13 additions & 0 deletions tests/data/fmtskip6.py
@@ -0,0 +1,13 @@
class A:
def f(self):
for line in range(10):
if True:
pass # fmt: skip

# output

class A:
def f(self):
for line in range(10):
if True:
pass # fmt: skip
1 change: 1 addition & 0 deletions tests/test_format.py
Expand Up @@ -41,6 +41,7 @@
"fmtskip3",
"fmtskip4",
"fmtskip5",
"fmtskip6",
"fstring",
"function",
"function2",
Expand Down