Skip to content

Commit

Permalink
Don't require whitespace right after match
Browse files Browse the repository at this point in the history
  • Loading branch information
isidentical committed Jan 23, 2022
1 parent 2345848 commit 50476f7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
5 changes: 0 additions & 5 deletions libcst/_nodes/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 28 additions & 0 deletions libcst/_nodes/tests/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 50476f7

Please sign in to comment.