8000 fix trio100 removing trailing comment with same-line with by jakkdl · Pull Request #186 · python-trio/flake8-async · GitHub
[go: up one dir, main page]

Skip to content

fix trio100 removing trailing comment with same-line with #186

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion flake8_trio/visitors/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,11 @@ def flatten_preserving_comments(node: cst.BaseCompoundStatement):
# and IndentedBlock
if isinstance(node.body, cst.SimpleStatementSuite):
# `with ...: pass;pass;pass` -> pass;pass;pass
return cst.SimpleStatementLine(node.body.body, leading_lines=new_leading_lines)
return cst.SimpleStatementLine(
node.body.body,
leading_lines=new_leading_lines,
trailing_whitespace=node.body.trailing_whitespace,
)

assert isinstance(node.body, cst.IndentedBlock)
nodes = list(node.body.body)
Expand Down
2 changes: 1 addition & 1 deletion tests/autofix_files/trio100.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

async def function_name():
# fmt: off
...; ...; ...
...; ...; ... # error: 15, "trio", "fail_after"
# fmt: on
# error: 15, "trio", "fail_after"
...
Expand Down
2 changes: 1 addition & 1 deletion tests/autofix_files/trio100.py.diff
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
async def function_name():
# fmt: off
- async with trio.fail_after(10): ...; ...; ... # error: 15, "trio", "fail_after"
+ ...; ...; ...
+ ...; ...; ... # error: 15, "trio", "fail_after"
# fmt: on
- async with trio.fail_after(10): # error: 15, "trio", "fail_after"
- ...
Expand Down
8 changes: 7 additions & 1 deletion tests/autofix_files/trio100_simple_autofix.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# a
# b
# fmt: off
...;...;...
...;...;... # error: 5, "trio", "move_on_after"
# fmt: on
# c
# d
Expand All @@ -51,3 +51,9 @@
# c
...; ...; ...
# fmt: on


# same-line with
# fmt: off
print(1) # TRIO100: 5, 'trio', 'fail_after'
# fmt: on
11 changes: 9 additions & 2 deletions tests/autofix_files/trio100_simple_autofix.py.diff
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
+++
@@ x,50 x,51 @@
@@ x,56 x,57 @@

# a
# b
Expand Down Expand Up @@ -41,7 +41,7 @@
# b
# fmt: off
-with trio.move_on_after(10): ...;...;... # error: 5, "trio", "move_on_after"
+...;...;...
+...;...;... # error: 5, "trio", "move_on_after"
# fmt: on
# c
# d
Expand Down Expand Up @@ -83,3 +83,10 @@
+# c
+...; ...; ...
# fmt: on


# same-line with
# fmt: off
-with trio.fail_after(5): print(1) # TRIO100: 5, 'trio', 'fail_after'
+print(1) # TRIO100: 5, 'trio', 'fail_after'
# fmt: on
6 changes: 6 additions & 0 deletions tests/eval_files/trio100_simple_autofix.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@
# c
): ...; ...; ...
# fmt: on


# same-line with
# fmt: off
with trio.fail_after(5): print(1) # TRIO100: 5, 'trio', 'fail_after'
# fmt: on
6 changes: 5 additions & 1 deletion tests/test_flake8_trio.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ def check_autofix(
" update the autofix files."
)
# and assert that the diff is the same, which it should be if the above passes
assert added_autofix_diff == autofix_diff_content
assert added_autofix_diff == autofix_diff_content, (
"THIS SHOULD NOT HAPPEN: diff in the autofix diff - without there being a diff"
" in the autofixed code, run with --generate-autofix if the test file has"
" changed to update the autofix files."
)


# This can be further cleaned up by adding the other return values from
Expand Down
0