diff options
author | Bill Wendling <morbo@google.com> | 2021-11-03 02:46:33 -0700 |
---|---|---|
committer | Bill Wendling <morbo@google.com> | 2021-11-03 02:46:33 -0700 |
commit | dbd49c3cffc1ffc382bfdd4c0979d444730c546d (patch) | |
tree | c4801248297d15d710f038f53930e00f6ec76baa | |
parent | 633744e62187b296e2f53b97defec4ac2eb9d5a6 (diff) | |
download | yapf-dbd49c3cffc1ffc382bfdd4c0979d444730c546d.tar.gz |
Enforce a space between a colon and the ... token
Closes #973
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | yapf/yapflib/unwrapped_line.py | 4 | ||||
-rw-r--r-- | yapftests/reformatter_pep8_test.py | 13 |
3 files changed, 16 insertions, 2 deletions
@@ -12,6 +12,7 @@ - Enable `BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF` knob for "pep8" style, so 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. ## [0.31.0] 2021-03-14 ### Added diff --git a/yapf/yapflib/unwrapped_line.py b/yapf/yapflib/unwrapped_line.py index b49fefe..ddd50e0 100644 --- a/yapf/yapflib/unwrapped_line.py +++ b/yapf/yapflib/unwrapped_line.py @@ -319,11 +319,11 @@ def _SpaceRequiredBetween(left, right, is_line_disabled): if lval == '.' and rval == 'import': # Space after the '.' in an import statement. return True - if (lval == '=' and rval == '.' and + if (lval == '=' and rval in {'.', ',,,'} and format_token.Subtype.DEFAULT_OR_NAMED_ASSIGN not in left.subtypes): # Space between equal and '.' as in "X = ...". return True - if lval == ':' and rval == '.': + if lval == ':' and rval in {'.', '...'}: # Space between : and ... return True if ((right.is_keyword or right.is_name) and diff --git a/yapftests/reformatter_pep8_test.py b/yapftests/reformatter_pep8_test.py index e1202c2..e5ed2fa 100644 --- a/yapftests/reformatter_pep8_test.py +++ b/yapftests/reformatter_pep8_test.py @@ -715,6 +715,19 @@ class _(): uwlines = yapf_test_helper.ParseAndUnwrap(code) self.assertCodeEqual(code, reformatter.Reformat(uwlines, verify=False)) + @unittest.skipUnless(py3compat.PY36, 'Requires Python 3.6') + def testSpaceBetweenDictColonAndElipses(self): + style.SetGlobalStyle(style.CreatePEP8Style()) + unformatted_code = textwrap.dedent("""\ + {0:"...", 1:...} + """) + expected_formatted_code = textwrap.dedent("""\ + {0: "...", 1: ...} + """) + + uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code) + self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines)) + class TestsForSpacesInsideBrackets(yapf_test_helper.YAPFTest): """Test the SPACE_INSIDE_BRACKETS style option.""" |