Skip to content

Commit

Permalink
fix: allow ParenthesizedWhitespace before params in FuncDef (#342)
Browse files Browse the repository at this point in the history
* fix: allow ParenthesizedWhitespace before params in FuncDef

Fixes #303

* fix: run codegen
  • Loading branch information
sk- authored Jul 15, 2020
1 parent f36eacb commit a9177e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libcst/_nodes/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ class FunctionDef(BaseCompoundStatement):

#: Whitespace after the opening parenthesis for the parameters but before
#: the first param itself.
whitespace_before_params: SimpleWhitespace = SimpleWhitespace.field("")
whitespace_before_params: BaseParenthesizableWhitespace = SimpleWhitespace.field("")

#: Whitespace after the closing parenthesis or return annotation and before
#: the colon.
Expand Down
16 changes: 16 additions & 0 deletions libcst/_nodes/tests/test_funcdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,22 @@ class FunctionDefCreationTest(CSTNodeTest):
"code": "* third",
"expected_position": CodeRange((1, 0), (1, 7)),
},
{
"node": cst.FunctionDef(
name=cst.Name(value="foo",),
params=cst.Parameters(
params=[cst.Param(name=cst.Name(value="param1",),),],
),
body=cst.IndentedBlock(
body=[cst.SimpleStatementLine(body=[cst.Pass(),],),],
),
whitespace_before_params=cst.ParenthesizedWhitespace(
last_line=cst.SimpleWhitespace(value=" ",),
),
),
"code": "def foo(\n param1):\n pass\n",
"expected_position": CodeRange((1, 0), (3, 8)),
},
)
)
def test_valid(self, **kwargs: Any) -> None:
Expand Down
6 changes: 3 additions & 3 deletions libcst/matchers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5799,10 +5799,10 @@ class FunctionDef(BaseCompoundStatement, BaseStatement, BaseMatcherNode):
AllOf[SimpleWhitespaceMatchType],
] = DoNotCare()
whitespace_before_params: Union[
SimpleWhitespaceMatchType,
BaseParenthesizableWhitespaceMatchType,
DoNotCareSentinel,
OneOf[SimpleWhitespaceMatchType],
AllOf[SimpleWhitespaceMatchType],
OneOf[BaseParenthesizableWhitespaceMatchType],
AllOf[BaseParenthesizableWhitespaceMatchType],
] = DoNotCare()
whitespace_before_colon: Union[
SimpleWhitespaceMatchType,
Expand Down

0 comments on commit a9177e2

Please sign in to comment.