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

Improve check for logical continuation in comprehension. #866

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
if verbose >= 3:
print(">>> " + tokens[0][4].rstrip())

for token_type, text, start, end, line in tokens:
for idx, (token_type, text, start, end, line) in enumerate(tokens):

newline = row < start[0] - first_row
if newline:
Expand Down Expand Up @@ -695,6 +695,10 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
elif (token_type in (tokenize.STRING, tokenize.COMMENT) or
text in ('u', 'ur', 'b', 'br')):
indent_chances[start[1]] = str
# hanging indents in comprehensions
elif (token_type == tokenize.NAME and text == "if" and
tokens[idx + 1][0] != tokenize.LPAR): # [0] == .type
indent_chances[tokens[idx + 1][2][1]] = True # [2] == .start
# special case for the "if" statement because len("if (") == 4
elif not indent_chances and not row and not depth and text == 'if':
indent_chances[end[1] + 1] = True
Expand Down
4 changes: 4 additions & 0 deletions testsuite/E12not.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,7 @@ def other_example():
# more stuff
)
)
#: W503
sorted(obj for obj in []
if True
and False)