Skip to content

Commit c873a24

Browse files
committed
remove lines from autofix diff, add CI tag management
1 parent c8061fe commit c873a24

11 files changed

+200
-106
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@ jobs:
5656
env:
5757
TWINE_USERNAME: __token__
5858
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
59-
run: python -m build && twine upload --skip-existing dist/*
59+
run: |
60+
python tests/test_version_and_changelog.py --ensure-tag
61+
python -m build && twine upload --skip-existing dist/*

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ repos:
4444
# Required for pyright strict mode
4545
- anyio
4646
- flake8
47+
- GitPython
4748
- hypothesis
4849
- hypothesmith
4950
- pytest

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
## Future
55
- TRIO91X now supports comprehensions
6+
- TRIO100 and TRIO91X now supports autofixing
7+
- Renamed `--enable-visitor-codes-regex` to `--enable`
8+
- Added `--disable`, `--autofix` and `--error-on-autofix`
69

710
## 23.2.5
811
- Fix false alarms for `@pytest.fixture`-decorated functions in TRIO101, TRIO910 and TRIO911

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,23 @@ pip install flake8-trio
6565

6666
## Configuration
6767
[You can configure `flake8` with command-line options](https://flake8.pycqa.org/en/latest/user/configuration.html),
68-
but we prefer using a config file. The file needs to start with a section marker `[flake8]` and the following options are then parsed using flake8's config parser, and can be used just like any other flake8 options.
68+
but we prefer using a config file. The file needs to start with a section marker `[flake8]` and the following options are then parsed using flake8's config parser, and can be used just like any other flake8 options.
69+
Note that it's not currently possible to use a configuration file when running flake8_trio standalone.
70+
71+
### `--enable`
72+
Comma-separated list of error codes to enable, similar to flake8 --select but is additionally more performant as it will disable non-enabled visitors from running instead of just silencing their errors.
73+
74+
### `--disable`
75+
Comma-separated list of error codes to disable, similar to flake8 --ignore but is additionally more performant as it will disable non-enabled visitors from running instead of just silencing their errors.
76+
77+
### `--autofix`
78+
Comma-separated list of error-codes to enable autofixing for if implemented. Requires running as a standalone program.
79+
80+
### `--error-on-autofix`
81+
Whether to also print an error message for autofixed errors.
82+
83+
### `--anyio`
84+
Change the default library to be anyio instead of trio. If trio is imported it will assume both are available and print suggestions with [anyio|trio].
6985

7086
### `no-checkpoint-warning-decorators`
7187
Specify a list of decorators to disable checkpointing checks for, turning off TRIO910 and TRIO911 warnings for functions decorated with any decorator matching any in the list. Matching is done with [fnmatch](https://docs.python.org/3/library/fnmatch.html). Defaults to disabling for `asynccontextmanager`.
@@ -120,3 +136,21 @@ async def my_function():
120136

121137
arbitrary_other_function(my_blocking_call=None)
122138
```
139+
140+
141+
### Using flake8_trio with pre-commit
142+
If you use [pre-commit](https://pre-commit.com/), you can use it with flake8_trio by
143+
adding the following to your `.pre-commit-config.yaml`:
144+
145+
```yaml
146+
minimum_pre_commit_version: '2.9.0'
147+
repos:
148+
- repo: https://github.com/Zac-HD/flake8-trio
149+
rev: 23.2.5
150+
hooks:
151+
- id: flake8-trio
152+
# args: [--enable=TRIO, --disable=TRIO9, --autofix=TRIO]
153+
```
154+
155+
This is often considerably faster for large projects, because `pre-commit`
156+
can avoid running `flake8_trio` on unchanged files.

tests/autofix_files/trio100.py.diff

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
+++
3-
@@ -3,24 +3,24 @@
3+
@@ x,24 x,24 @@
44

55
import trio
66

@@ -38,7 +38,7 @@
3838

3939
with trio.move_on_after(10):
4040
await trio.sleep(1)
41-
@@ -37,8 +37,8 @@
41+
@@ x,8 x,8 @@
4242
with open("filename") as _:
4343
...
4444

@@ -49,7 +49,7 @@
4949

5050
send_channel, receive_channel = trio.open_memory_channel(0)
5151
async with trio.fail_after(10):
52-
@@ -49,22 +49,22 @@
52+
@@ x,22 x,22 @@
5353
async for _ in receive_channel:
5454
...
5555

tests/autofix_files/trio100_simple_autofix.py.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
+++
3-
@@ -3,50 +3,51 @@
3+
@@ x,50 x,51 @@
44

55
# a
66
# b

tests/autofix_files/trio910.py.diff

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
+++
3-
@@ -45,12 +45,14 @@
3+
@@ x,12 x,14 @@
44

55
async def foo1(): # error: 0, "exit", Statement("function definition", lineno)
66
bar()
@@ -15,23 +15,23 @@
1515

1616

1717
async def foo_if_2():
18-
@@ -81,6 +83,7 @@
18+
@@ x,6 x,7 @@
1919

2020
async def foo_ifexp_2(): # error: 0, "exit", Statement("function definition", lineno)
2121
print(_ if False and await foo() else await foo())
2222
+ await trio.lowlevel.checkpoint()
2323

2424

2525
# nested function definition
26-
@@ -89,6 +92,7 @@
26+
@@ x,6 x,7 @@
2727

2828
async def foo_func_2(): # error: 4, "exit", Statement("function definition", lineno)
2929
bar()
3030
+ await trio.lowlevel.checkpoint()
3131

3232

3333
# we don't get a newline after the nested function definition before the checkpoint
34-
@@ -97,17 +101,21 @@
34+
@@ x,17 x,21 @@
3535
async def foo_func_3(): # error: 0, "exit", Statement("function definition", lineno)
3636
async def foo_func_4():
3737
await foo()
@@ -53,7 +53,7 @@
5353
# fmt: on
5454

5555

56-
@@ -144,11 +152,13 @@
56+
@@ x,11 x,13 @@
5757
async def foo_condition_2(): # error: 0, "exit", Statement("function definition", lineno)
5858
if False and await foo():
5959
...
@@ -67,15 +67,15 @@
6767

6868

6969
async def foo_condition_4(): # safe
70-
@@ -170,6 +180,7 @@
70+
@@ x,6 x,7 @@
7171
async def foo_while_1(): # error: 0, "exit", Statement("function definition", lineno)
7272
while _:
7373
await foo()
7474
+ await trio.lowlevel.checkpoint()
7575

7676

7777
async def foo_while_2(): # now safe
78-
@@ -188,12 +199,14 @@
78+
@@ x,12 x,14 @@
7979
async def foo_while_4(): # error: 0, "exit", Statement("function definition", lineno)
8080
while False:
8181
await foo()
@@ -90,71 +90,71 @@
9090

9191

9292
async def foo_for_2(): # now safe
93-
@@ -216,6 +229,7 @@
93+
@@ x,6 x,7 @@
9494
break
9595
else:
9696
await foo()
9797
+ await trio.lowlevel.checkpoint()
9898

9999

100100
async def foo_while_break_3(): # error: 0, "exit", Statement("function definition", lineno)
101-
@@ -224,6 +238,7 @@
101+
@@ x,6 x,7 @@
102102
break
103103
else:
104104
...
105105
+ await trio.lowlevel.checkpoint()
106106

107107

108108
async def foo_while_break_4(): # error: 0, "exit", Statement("function definition", lineno)
109-
@@ -231,6 +246,7 @@
109+
@@ x,6 x,7 @@
110110
break
111111
else:
112112
...
113113
+ await trio.lowlevel.checkpoint()
114114

115115

116116
async def foo_while_continue_1(): # safe
117-
@@ -254,6 +270,7 @@
117+
@@ x,6 x,7 @@
118118
continue
119119
else:
120120
...
121121
+ await trio.lowlevel.checkpoint()
122122

123123

124124
async def foo_while_continue_4(): # error: 0, "exit", Statement("function definition", lineno)
125-
@@ -261,6 +278,7 @@
125+
@@ x,6 x,7 @@
126126
continue
127127
else:
128128
...
129129
+ await trio.lowlevel.checkpoint()
130130

131131

132132
async def foo_async_for_1():
133-
@@ -299,6 +317,7 @@
133+
@@ x,6 x,7 @@
134134
raise
135135
else:
136136
await foo()
137137
+ await trio.lowlevel.checkpoint()
138138

139139

140140
async def foo_try_2(): # safe
141-
@@ -349,6 +368,7 @@
141+
@@ x,6 x,7 @@
142142
pass
143143
else:
144144
pass
145145
+ await trio.lowlevel.checkpoint()
146146

147147

148148
async def foo_try_7(): # safe
149-
@@ -390,6 +410,7 @@
149+
@@ x,6 x,7 @@
150150
await trio.sleep(0)
151151
except:
152152
...
153153
+ await trio.lowlevel.checkpoint()
154154

155155

156156
# safe
157-
@@ -417,16 +438,19 @@
157+
@@ x,16 x,19 @@
158158
except:
159159
...
160160
finally:
@@ -174,15 +174,15 @@
174174
return # error: 8, "return", Statement("function definition", lineno-2)
175175
await foo()
176176

177-
@@ -435,6 +459,7 @@
177+
@@ x,6 x,7 @@
178178
if _:
179179
await foo()
180180
return # safe
181181
+ await trio.lowlevel.checkpoint()
182182

183183

184184
# loop over non-empty static collection
185-
@@ -462,12 +487,14 @@
185+
@@ x,12 x,14 @@
186186
async def foo_range_4(): # error: 0, "exit", Statement("function definition", lineno)
187187
for i in range(10, 5):
188188
await foo()
@@ -197,7 +197,7 @@
197197

198198

199199
# https://github.com/Zac-HD/flake8-trio/issues/47
200-
@@ -551,6 +578,7 @@
200+
@@ x,6 x,7 @@
201201
# should error
202202
async def foo_comprehension_2(): # error: 0, "exit", Statement("function definition", lineno)
203203
[await foo() for x in range(10) if bar()]

0 commit comments

Comments
 (0)