Skip to content

Commit 03e8d14

Browse files
committed
fix: fix tab-space mix with tab indenation and continuation_align_style=SPACE
1 parent 633744e commit 03e8d14

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

yapf/yapflib/format_token.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def _TabbedContinuationAlignPadding(spaces, align_style, tab_width):
7777
if spaces > 0:
7878
return '\t' * int((spaces + tab_width - 1) / tab_width)
7979
return ''
80-
return ' ' * spaces
80+
if spaces % tab_width == 0:
81+
return '\t' * (spaces // tab_width)
82+
return ' ' * spaces # TODO: add a comment why we indent with spaces in a tab area?
8183

8284

8385
class FormatToken(object):

yapftests/format_token_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def testSpace(self):
3030
self.assertEqual(pad, '')
3131

3232
pad = format_token._TabbedContinuationAlignPadding(2, align_style, 2)
33-
self.assertEqual(pad, ' ' * 2)
33+
self.assertEqual(pad, '\t')
3434

3535
pad = format_token._TabbedContinuationAlignPadding(5, align_style, 2)
3636
self.assertEqual(pad, ' ' * 5)

yapftests/yapf_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,8 +1268,8 @@ def f():
12681268
expected_formatted_code = """\
12691269
def f():
12701270
return [
1271-
'hello',
1272-
'world',
1271+
'hello',
1272+
'world',
12731273
]
12741274
"""
12751275
style_contents = u"""\

0 commit comments

Comments
 (0)