From 50476f7eb739dda752d7e36d3a5803257544f899 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Sun, 23 Jan 2022 22:54:50 +0300 Subject: [PATCH] Don't require whitespace right after match --- libcst/_nodes/statement.py | 5 ----- libcst/_nodes/tests/test_match.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/libcst/_nodes/statement.py b/libcst/_nodes/statement.py index ded7c7c6c..0e1cefe68 100644 --- a/libcst/_nodes/statement.py +++ b/libcst/_nodes/statement.py @@ -2687,11 +2687,6 @@ def _validate(self) -> None: if len(self.cases) == 0: raise CSTValidationError("A match statement must have at least one case.") - if self.whitespace_after_match.empty: - raise CSTValidationError( - "Must have at least one space after a 'match' keyword" - ) - indent = self.indent if indent is not None: if len(indent) == 0: diff --git a/libcst/_nodes/tests/test_match.py b/libcst/_nodes/tests/test_match.py index edf51d846..5ceea72c1 100644 --- a/libcst/_nodes/tests/test_match.py +++ b/libcst/_nodes/tests/test_match.py @@ -425,6 +425,34 @@ class MatchTest(CSTNodeTest): + " case None | False | True: pass\n", "parser": None, }, + # Match without whitespace between keyword and the expr + { + "node": cst.Match( + subject=cst.Name( + "x", lpar=[cst.LeftParen()], rpar=[cst.RightParen()] + ), + cases=[ + cst.MatchCase( + pattern=cst.MatchSingleton( + cst.Name( + "None", + lpar=[cst.LeftParen()], + rpar=[cst.RightParen()], + ) + ), + body=cst.SimpleStatementSuite((cst.Pass(),)), + whitespace_after_case=cst.SimpleWhitespace( + value="", + ), + ), + ], + whitespace_after_match=cst.SimpleWhitespace( + value="", + ), + ), + "code": "match(x):\n case(None): pass\n", + "parser": parser, + }, ) ) def test_valid(self, **kwargs: Any) -> None: