8000 fix TRIO100 removing trailing comment in same-line with · python-trio/flake8-async@ec5f15a · GitHub
[go: up one dir, main page]

Skip to content

Commit ec5f15a

Browse files
committed
fix TRIO100 removing trailing comment in same-line with
1 parent e13a686 commit ec5f15a

File tree

7 files changed

+34
-7
lines changed

7 files changed

+34
-7
lines changed

flake8_trio/visitors/helpers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,11 @@ def flatten_preserving_comments(node: cst.BaseCompoundStatement):
377377
# and IndentedBlock
378378
if isinstance(node.body, cst.SimpleStatementSuite):
379379
# `with ...: pass;pass;pass` -> pass;pass;pass
380-
return cst.SimpleStatementLine(node.body.body, leading_lines=new_leading_lines)
380+
return cst.SimpleStatementLine(
381+
node.body.body,
382+
leading_lines=new_leading_lines,
383+
trailing_whitespace=node.body.trailing_whitespace,
384+
)
381385

382386
assert isinstance(node.body, cst.IndentedBlock)
383387
nodes = list(node.body.body)

tests/autofix_files/trio100.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
async def function_name():
1111
# fmt: off
12-
...; ...; ...
12+
...; ...; ... # error: 15, "trio", "fail_after"
1313
# fmt: on
1414
# error: 15, "trio", "fail_after"
1515
...

tests/autofix_files/trio100.py.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
async def function_name():
1414
# fmt: off
1515
- async with trio.fail_after(10): ...; ...; ... # error: 15, "trio", "fail_after"
16-
+ ...; ...; ...
16+
+ ...; ...; ... # error: 15, "trio", "fail_after"
1717
# fmt: on
1818
- async with trio.fail_after(10): # error: 15, "trio", "fail_after"
1919
- ...

tests/autofix_files/trio100_simple_autofix.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# a
2626
# b
2727
# fmt: off
28-
...;...;...
28+
...;...;... # error: 5, "trio", "move_on_after"
2929
# fmt: on
3030
# c
3131
# d
@@ -51,3 +51,9 @@
5151
# c
5252
...; ...; ...
5353
# fmt: on
54+
55+
56+
# same-line with
57+
# fmt: off
58+
print(1) # TRIO100: 5, 'trio', 'fail_after'
59+
# fmt: on

tests/autofix_files/trio100_simple_autofix.py.diff

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
+++
3-
@@ x,50 x,51 @@
3+
@@ x,56 x,57 @@
44

55
# a
66
# b
@@ -41,7 +41,7 @@
4141
# b
4242
# fmt: off
4343
-with trio.move_on_after(10): ...;...;... # error: 5, "trio", "move_on_after"
44-
+...;...;...
44+
+...;...;... # error: 5, "trio", "move_on_after"
4545
# fmt: on
4646
# c
4747
# d
@@ -83,3 +83,10 @@
8383
+# c
8484
+...; ...; ...
8585
# fmt: on
86+
87+
88+
# same-line with
89+
# fmt: off
90+
-with trio.fail_after(5): print(1) # TRIO100: 5, 'trio', 'fail_after'
91+
+print(1) # TRIO100: 5, 'trio', 'fail_after'
92+
# fmt: on

tests/eval_files/trio100_simple_autofix.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@
5050
# c
5151
): ...; ...; ...
5252
# fmt: on
53+
54+
55+
# same-line with
56+
# fmt: off
57+
with trio.fail_after(5): print(1) # TRIO100: 5, 'trio', 'fail_after'
58+
# fmt: on

tests/test_flake8_trio.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ def check_autofix(
164164
" update the autofix files."
165165
)
166166
# and assert that the diff is the same, which it should be if the above passes
167-
assert added_autofix_diff == autofix_diff_content
167+
assert added_autofix_diff == autofix_diff_content, (
168+
"THIS SHOULD NOT HAPPEN: diff in the autofix diff - without there being a diff"
169+
" in the autofixed code, run with --generate-autofix if the test file has"
170+
" changed to update the autofix files."
171+
)
168172

169173

170174
# This can be further cleaned up by adding the other return values from

0 commit comments

Comments
 (0)
0