You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://microsoft.github.io/pyright/)
3
-
# flake8-trio
3
+
# flake8-async
4
4
5
-
A highly opinionated flake8 plugin for [Trio](https://github.com/python-trio/trio)-related problems.
5
+
A highly opinionated flake8 plugin for problems related to [Trio](https://github.com/python-trio/trio), [AnyIO](https://github.com/agronholm/anyio), or [asyncio](https://docs.python.org/3/library/asyncio.html).
6
6
7
7
This can include anything from outright bugs, to pointless/dead code,
8
8
to likely performance issues, to minor points of idiom that might signal
9
9
a misunderstanding.
10
10
11
11
It may well be too noisy for anyone with different opinions, that's OK.
12
12
13
-
It also supports the [anyio](https://github.com/agronholm/anyio) library.
14
-
15
13
Pairs well with flake8-bugbear.
16
14
15
+
Some checks are incorporated into [ruff](https://github.com/astral-sh/ruff).
16
+
17
+
This plugin was previously known as flake8-trio, and there was a separate small plugin known as flake8-async for asyncio. But this plugin was a superset of the checks in flake8-async, and support for anyio was added, so it's now named flake8-async to more properly convey its usage. At the same time all error codes were renamed from TRIOxxx to ASYNCxxx, as was previously used by the old flake8-async.
18
+
17
19
## Installation
18
20
19
21
```console
20
-
pip install flake8-trio
22
+
pip install flake8-async
21
23
```
22
24
23
25
## List of warnings
@@ -31,7 +33,7 @@ pip install flake8-trio
31
33
-**TRIO103**: `except BaseException`, `except trio.Cancelled` or a bare `except:` with a code path that doesn't re-raise. If you don't want to re-raise `BaseException`, add a separate handler for `trio.Cancelled` before.
32
34
-**TRIO104**: `Cancelled` and `BaseException` must be re-raised - when a user tries to `return` or `raise` a different exception.
33
35
-**TRIO105**: Calling a trio async function without immediately `await`ing it.
34
-
-**TRIO106**: `trio` must be imported with `import trio` for the linter to work.
36
+
-**TRIO106**: `trio`/`anyio` must be imported with `import trio`/`import anyio` for the linter to work.
35
37
-**TRIO107**: Renamed to TRIO910
36
38
-**TRIO108**: Renamed to TRIO911
37
39
-**TRIO109**: Async function definition with a `timeout` parameter - use `trio.[fail/move_on]_[after/at]` instead
@@ -68,55 +70,55 @@ pip install flake8-trio
68
70
## Examples
69
71
### install and run through flake8
70
72
```sh
71
-
pip install flake8 flake8-trio
73
+
pip install flake8 flake8-async
72
74
flake8 .
73
75
```
74
76
### install and run with pre-commit
75
-
If you use [pre-commit](https://pre-commit.com/), you can use it with flake8-trio by
77
+
If you use [pre-commit](https://pre-commit.com/), you can use it with flake8-async by
76
78
adding the following to your `.pre-commit-config.yaml`:
This is often considerably faster for large projects, because `pre-commit`
89
-
can avoid running `flake8-trio` on unchanged files.
91
+
can avoid running `flake8-async` on unchanged files.
90
92
91
93
92
94
Afterwards, run
93
95
```sh
94
-
pip install pre-commit flake8-trio
96
+
pip install pre-commit flake8-async
95
97
pre-commit run .
96
98
```
97
99
### install and run as standalone
98
100
If inside a git repository, running without arguments will run it against all `*.py` files in the repository.
99
101
```sh
100
-
pip install flake8-trio
101
-
flake8-trio
102
+
pip install flake8-async
103
+
flake8-async
102
104
```
103
105
#### with autofixes
104
106
```sh
105
-
flake8-trio --autofix=TRIO
107
+
flake8-async --autofix=ASYNC
106
108
```
107
109
#### specifying source files
108
110
```sh
109
-
flake8-trio my_python_file.py
111
+
flake8-async my_python_file.py
110
112
```
111
113
##### zsh-only
112
114
```zsh
113
-
flake8-trio**/*.py
115
+
flake8-async**/*.py
114
116
```
115
117
116
118
## Configuration
117
119
[You can configure `flake8` with command-line options](https://flake8.pycqa.org/en/latest/user/configuration.html),
118
120
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.
119
-
Note that it's not currently possible to use a configuration file when running `flake8-trio` standalone.
121
+
Note that it's not currently possible to use a configuration file when running `flake8-async` standalone.
120
122
121
123
### `--enable`
122
124
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.
@@ -125,7 +127,7 @@ Comma-separated list of error codes to enable, similar to flake8 --select but is
125
127
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.
126
128
127
129
### `--autofix`
128
-
Comma-separated list of error-codes to enable autofixing for if implemented. Requires running as a standalone program. Pass `--autofix=TRIO` to enable all autofixes.
130
+
Comma-separated list of error-codes to enable autofixing for if implemented. Requires running as a standalone program. Pass `--autofix=ASYNC` to enable all autofixes.
129
131
130
132
### `--error-on-autofix`
131
133
Whether to also print an error message for autofixed errors.
@@ -134,7 +136,7 @@ Whether to also print an error message for autofixed errors.
134
136
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].
135
137
136
138
### `no-checkpoint-warning-decorators`
137
-
Comma-separated 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`.
139
+
Comma-separated list of decorators to disable checkpointing checks for, turning off ASYNC910 and ASYNC911 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`.
138
140
139
141
Decorators-to-match must be identifiers or dotted names only (not PEP-614 expressions), and will match against the name only - e.g. `foo.bar` matches `foo.bar`, `foo.bar()`, and `foo.bar(args, here)`, etc.
Comma-separated list of pairs of values separated by `->` (optional whitespace stripped), where the first is a pattern for a call that should raise an error if found inside an async function, and the second is what should be suggested to use instead. It uses fnmatch as per [`no-checkpoint-warning-decorators`](#no-checkpoint-warning-decorators) for matching. The part after `->` is not used by the checker other than when printing the error, so you could add extra info there if you want.
163
165
164
166
The format of the error message is `User-configured blocking sync call {0} in async function, consider replacing with {1}.`, where `{0}` is the pattern the call matches and `{1}` is the suggested replacement.
165
167
166
168
Example:
167
169
```ini
168
-
trio200-blocking-calls =
170
+
async200-blocking-calls =
169
171
my_blocking_call -> async.alternative,
170
172
module.block_call -> other_function_to_use,
171
173
common_error_call -> alternative(). But sometimes you should use other_function(). Ask joe if you're unsure which one,
0 commit comments