Skip to content

Commit f9cd73c

Browse files
committed
fix: fix tab-space mix with tab indenation and continuation_align_style=SPACE
1 parent dbd49c3 commit f9cd73c

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CHANGELOG

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
method definitions inside a class are surrounded by a single blank line as
1414
prescribed by PEP8.
1515
- Fixed the '...' token to be spaced after a colon.
16+
- With `USE_TABS=True` and `continuation_align_style=SPACE` no space tab mix
17+
is produced anymore.
1618

1719
## [0.31.0] 2021-03-14
1820
### Added

yapf/yapflib/format_token.py

+3-1
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 tab_width > 1 and 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

+1-1
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)

0 commit comments

Comments
 (0)