Skip to content

Commit 686c84b

Browse files
authored
Merge pull request #912 from anntzer/vindentwith
Support visual indent of continuation lines after with/assert/raise.
2 parents 68cc24f + b36fba6 commit 686c84b

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

pycodestyle.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
695695
elif (token_type in (tokenize.STRING, tokenize.COMMENT) or
696696
text in ('u', 'ur', 'b', 'br')):
697697
indent_chances[start[1]] = str
698+
# visual indent after assert/raise/with
699+
elif not row and not depth and text in ["assert", "raise", "with"]:
700+
indent_chances[end[1] + 1] = True
698701
# special case for the "if" statement because len("if (") == 4
699702
elif not indent_chances and not row and not depth and text == 'if':
700703
indent_chances[end[1] + 1] = True

testsuite/E12.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,26 @@ def example_issue254():
372372

373373
print(a
374374
, end=' ')
375-
#:
375+
#: E127:4:12
376+
def foo():
377+
pass
378+
raise 123 + \
379+
123
380+
#: E127:4:13
381+
class Eggs:
382+
pass
383+
assert 123456 == \
384+
123456
385+
#: E127:4:11
386+
def f1():
387+
print('foo')
388+
with open('/path/to/some/file/you/want/to/read') as file_1, \
389+
open('/path/to/some/file/being/written', 'w') as file_2:
390+
file_2.write(file_1.read())
391+
#: E127:5:11
392+
def f1():
393+
print('foo')
394+
with open('/path/to/some/file/you/want/to/read') as file_1, \
395+
open('/path/to/some/file/being/written', 'w') as file_2, \
396+
open('later-misindent'):
397+
file_2.write(file_1.read())

testsuite/E12not.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,3 +639,23 @@ def other_example():
639639
# more stuff
640640
)
641641
)
642+
643+
644+
def foo():
645+
pass
646+
raise 123 + \
647+
123
648+
649+
650+
class Eggs:
651+
pass
652+
assert 123456 == \
653+
123456
654+
655+
656+
def f1():
657+
print('foo')
658+
with open('/path/to/some/file/you/want/to/read') as file_1, \
659+
open('/path/to/some/file/being/written', 'w') as file_2, \
660+
open('just-making-sure-more-continuations-also-work'):
661+
file_2.write(file_1.read())

0 commit comments

Comments
 (0)