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

Detect '@' dotted_name '(' ')' NEWLINE as a simple decorator #2182

Merged
merged 1 commit into from May 4, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Expand Up @@ -6,6 +6,9 @@

- Set `--pyi` mode if `--stdin-filename` ends in `.pyi` (#2169)

- Stop detecting target version as Python 3.9+ with pre-PEP-614 decorators that are
being called but with no arguments (#2182)

### 21.4b2

#### _Black_
Expand Down
7 changes: 7 additions & 0 deletions src/black/__init__.py
Expand Up @@ -5761,6 +5761,13 @@ def is_simple_decorator_trailer(node: LN, last: bool = False) -> bool:
and node.children[0].type == token.DOT
and node.children[1].type == token.NAME
)
# last trailer can be an argument-less parentheses pair
or (
last
and len(node.children) == 2
and node.children[0].type == token.LPAR
and node.children[1].type == token.RPAR
)
# last trailer can be arguments
or (
last
Expand Down
6 changes: 6 additions & 0 deletions tests/data/decorators.py
Expand Up @@ -13,6 +13,12 @@ def f():

##

@decorator()
def f():
...

##

@decorator(arg)
def f():
...
Expand Down