From 5f073ca2b96d2c1e164cbebd10bdb0abb5749b81 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Sun, 23 Jan 2022 18:57:26 +0300 Subject: [PATCH] Proxy both parentheses in some pattern matching nodes --- libcst/_nodes/statement.py | 17 +++++++++++++++ libcst/_nodes/tests/test_match.py | 35 +++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/libcst/_nodes/statement.py b/libcst/_nodes/statement.py index ded7c7c6c..adb3573da 100644 --- a/libcst/_nodes/statement.py +++ b/libcst/_nodes/statement.py @@ -2848,6 +2848,14 @@ def lpar(self) -> Sequence[LeftParen]: def lpar(self, value: Sequence[LeftParen]) -> None: self.value.lpar = value + @property + def rpar(self) -> Sequence[RightParen]: + return self.value.rpar + + @rpar.setter + def rpar(self, value: Sequence[RightParen]) -> None: + self.value.rpar = value + @add_slots @dataclass(frozen=True) @@ -2881,6 +2889,15 @@ def lpar(self, value: Sequence[LeftParen]) -> None: # pyre-fixme[41]: Cannot reassign final attribute `lpar`. self.value.lpar = value + @property + def rpar(self) -> Sequence[RightParen]: + return self.value.rpar + + @rpar.setter + def rpar(self, value: Sequence[RightParen]) -> None: + # pyre-fixme[41]: Cannot reassign final attribute `rpar`. + self.value.rpar = value + @add_slots @dataclass(frozen=True) diff --git a/libcst/_nodes/tests/test_match.py b/libcst/_nodes/tests/test_match.py index edf51d846..75b1596b6 100644 --- a/libcst/_nodes/tests/test_match.py +++ b/libcst/_nodes/tests/test_match.py @@ -39,6 +39,41 @@ class MatchTest(CSTNodeTest): + ' case "foo": pass\n', "parser": parser, }, + # Parenthesized value + { + "node": cst.Match( + subject=cst.Name( + value="x", + ), + cases=[ + cst.MatchCase( + pattern=cst.MatchAs( + pattern=cst.MatchValue( + value=cst.Integer( + value="1", + lpar=[ + cst.LeftParen(), + ], + rpar=[ + cst.RightParen(), + ], + ), + ), + name=cst.Name( + value="z", + ), + whitespace_before_as=cst.SimpleWhitespace(" "), + whitespace_after_as=cst.SimpleWhitespace(" "), + ), + body=cst.SimpleStatementSuite( + [cst.Pass()] + ), + ), + ], + ), + "code": "match x:\n case (1) as z: pass\n", + "parser": parser, + }, # List patterns { "node": cst.Match(