Skip to content

Commit

Permalink
allow any expression
Browse files Browse the repository at this point in the history
  • Loading branch information
zsol committed May 22, 2023
1 parent a68ac53 commit ff1a680
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
3 changes: 1 addition & 2 deletions libcst/_nodes/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
BaseAssignTargetExpression,
BaseDelTargetExpression,
BaseExpression,
Call,
ConcatenatedString,
ExpressionPosition,
From,
Expand Down Expand Up @@ -1619,7 +1618,7 @@ class Decorator(CSTNode):

#: The decorator that will return a new function wrapping the parent
#: of this decorator.
decorator: Union[Name, Attribute, Call]
decorator: BaseExpression

#: Line comments and empty lines before this decorator. The parent
#: :class:`FunctionDef` or :class:`ClassDef` node owns leading lines before
Expand Down
14 changes: 14 additions & 0 deletions libcst/_nodes/tests/test_funcdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,20 @@ class FunctionDefCreationTest(CSTNodeTest):
),
"code": "@bar()()\ndef foo(): pass\n",
},
# Allow nested calls on decorator
{
"node": cst.FunctionDef(
cst.Name("foo"),
cst.Parameters(),
cst.SimpleStatementSuite((cst.Pass(),)),
(
cst.Decorator(
cst.BinaryOperation(cst.Name("a"), cst.Add(), cst.Name("b"))
),
),
),
"code": "@a + b\ndef foo(): pass\n",
},
# Allow parentheses around decorator
{
"node": cst.FunctionDef(
Expand Down
13 changes: 3 additions & 10 deletions libcst/matchers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3089,13 +3089,6 @@ class Continue(BaseSmallStatement, BaseMatcherNode):
] = DoNotCare()


NameOrAttributeOrCallMatchType = Union[
"Name",
"Attribute",
"Call",
MetadataMatchType,
MatchIfTrue[Union[cst.Name, cst.Attribute, cst.Call]],
]
TrailingWhitespaceMatchType = Union[
"TrailingWhitespace", MetadataMatchType, MatchIfTrue[cst.TrailingWhitespace]
]
Expand All @@ -3104,10 +3097,10 @@ class Continue(BaseSmallStatement, BaseMatcherNode):
@dataclass(frozen=True, eq=False, unsafe_hash=False)
class Decorator(BaseMatcherNode):
decorator: Union[
NameOrAttributeOrCallMatchType,
BaseExpressionMatchType,
DoNotCareSentinel,
OneOf[NameOrAttributeOrCallMatchType],
AllOf[NameOrAttributeOrCallMatchType],
OneOf[BaseExpressionMatchType],
AllOf[BaseExpressionMatchType],
] = DoNotCare()
leading_lines: Union[
Sequence[
Expand Down

0 comments on commit ff1a680

Please sign in to comment.