Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/docformatter/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def is_nested_definition_line(token: tokenize.TokenInfo) -> bool:
bool
True if the token is a nested definition line, False otherwise.
"""
return re.match(r"^ {4,}(async|class|def) ", token.line) is not None
return re.match(r"^ {4,}(?:async def|class|def) ", token.line) is not None


def is_newline_continuation(
Expand Down
8 changes: 8 additions & 0 deletions tests/_data/string_files/classify_functions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ end = "(3,25)"
line = ' async def foo():\n'
expected = true

[is_not_nested_definition_line_async_with]
type = 1
string = ' async with lock:\n'
start = "(3,10)"
end = "(3,30)"
line = ' async with lock:\n'
expected = false

[is_not_nested_definition_line_function]
type = 1
string = ' definitely\n'
Expand Down
12 changes: 12 additions & 0 deletions tests/_data/string_files/do_format_code.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,18 @@ expected='''"""A."""
pass
'''

[issue_351]
source='''async def example() -> None:
"""Example."""
async with lock:
pass
'''
expected='''async def example() -> None:
"""Example."""
async with lock:
pass
'''

# A blank line with trailing whitespace must not crash the tokenizer round-trip.
# The "\n" escapes are used so the four trailing spaces on the blank line are
# explicit and cannot be stripped by editors or formatters.
Expand Down
1 change: 1 addition & 0 deletions tests/formatter/test_do_format_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
("do_not_break_f_string_double_quotes", NO_ARGS),
("do_not_break_f_string_single_quotes", NO_ARGS),
("issue_331_black_module_docstring", ["--black", ""]),
("issue_351", NO_ARGS),
("issue_355", NO_ARGS),
("issue_360_no_trailing_newline", NO_ARGS),
],
Expand Down
1 change: 1 addition & 0 deletions tests/test_classify_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def test_is_not_attribute_docstring_inside_brackets(source):
("is_nested_definition_line_class", is_nested_definition_line),
("is_nested_definition_line_function", is_nested_definition_line),
("is_nested_definition_line_async_function", is_nested_definition_line),
("is_not_nested_definition_line_async_with", is_nested_definition_line),
("is_not_nested_definition_line_function", is_nested_definition_line),
("is_newline_continuation", is_newline_continuation),
("is_string_variable", is_string_variable),
Expand Down