Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't require whitespace right after match #628

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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