diff --git a/CHANGELOG b/CHANGELOG index 19d59f8e0..3b445fd87 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,8 @@ method definitions inside a class are surrounded by a single blank line as prescribed by PEP8. - Fixed the '...' token to be spaced after a colon. +- With `USE_TABS=True` and `continuation_align_style=SPACE` no space tab mix + is produced anymore. ## [0.31.0] 2021-03-14 ### Added diff --git a/yapf/yapflib/format_token.py b/yapf/yapflib/format_token.py index 92c26ee57..ee638aa4c 100644 --- a/yapf/yapflib/format_token.py +++ b/yapf/yapflib/format_token.py @@ -77,7 +77,9 @@ def _TabbedContinuationAlignPadding(spaces, align_style, tab_width): if spaces > 0: return '\t' * int((spaces + tab_width - 1) / tab_width) return '' - return ' ' * spaces + if tab_width > 1 and spaces % tab_width == 0: + return '\t' * (spaces // tab_width) + return ' ' * spaces # TODO: add a comment why we indent with spaces in a tab area? class FormatToken(object): diff --git a/yapftests/format_token_test.py b/yapftests/format_token_test.py index b4c715107..a1662cb6f 100644 --- a/yapftests/format_token_test.py +++ b/yapftests/format_token_test.py @@ -30,7 +30,7 @@ def testSpace(self): self.assertEqual(pad, '') pad = format_token._TabbedContinuationAlignPadding(2, align_style, 2) - self.assertEqual(pad, ' ' * 2) + self.assertEqual(pad, '\t') pad = format_token._TabbedContinuationAlignPadding(5, align_style, 2) self.assertEqual(pad, ' ' * 5)