Skip to content

Commit

Permalink
Proxy both parentheses in some pattern matching nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
isidentical committed Jan 23, 2022
1 parent 2b2b25b commit 9110754
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
17 changes: 17 additions & 0 deletions libcst/_nodes/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions libcst/_nodes/tests/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,39 @@ 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(
Expand Down

0 comments on commit 9110754

Please sign in to comment.