Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a91e5ce

Browse files
committedFeb 23, 2024
update docs, name of binary, and in general all changes possible without renaming files
1 parent dffdf7d commit a91e5ce

9 files changed

+44
-44
lines changed
 

‎.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: flake8-trio CI
2+
name: flake8-async CI
33

44
on:
55
push:

‎CONTRIBUTING.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ Contributions welcome! We'll expand this guide as we go.
55

66
## Development
77

8-
When you wish to add a check to `flake8-trio` please ensure the following:
8+
When you wish to add a check to `flake8-async` please ensure the following:
99

1010
- `README.md` gets a one line about your new warning
1111
- Add a CHANGELOG entry (see 'Releasing a new version' below)
12-
- Unittests are added showing the check highlight where it should and shouldn't
13-
(see flake8-bugbear for examples of good linter tests)
14-
12+
- A test in `tests/eval_files` is added for your check. See the "Test generator" heading below.
1513
To run our test suite please use tox.
1614

1715
```console

‎README.md

+25-23
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/python-trio/flake8-trio/main.svg)](https://results.pre-commit.ci/latest/github/python-trio/flake8-trio/main)
22
[![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)
3-
# flake8-trio
3+
# flake8-async
44

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).
66

77
This can include anything from outright bugs, to pointless/dead code,
88
to likely performance issues, to minor points of idiom that might signal
99
a misunderstanding.
1010

1111
It may well be too noisy for anyone with different opinions, that's OK.
1212

13-
It also supports the [anyio](https://github.com/agronholm/anyio) library.
14-
1513
Pairs well with flake8-bugbear.
1614

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+
1719
## Installation
1820

1921
```console
20-
pip install flake8-trio
22+
pip install flake8-async
2123
```
2224

2325
## List of warnings
@@ -31,7 +33,7 @@ pip install flake8-trio
3133
- **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.
3234
- **TRIO104**: `Cancelled` and `BaseException` must be re-raised - when a user tries to `return` or `raise` a different exception.
3335
- **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.
3537
- **TRIO107**: Renamed to TRIO910
3638
- **TRIO108**: Renamed to TRIO911
3739
- **TRIO109**: Async function definition with a `timeout` parameter - use `trio.[fail/move_on]_[after/at]` instead
@@ -68,55 +70,55 @@ pip install flake8-trio
6870
## Examples
6971
### install and run through flake8
7072
```sh
71-
pip install flake8 flake8-trio
73+
pip install flake8 flake8-async
7274
flake8 .
7375
```
7476
### 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
7678
adding the following to your `.pre-commit-config.yaml`:
7779

7880
```yaml
7981
minimum_pre_commit_version: '2.9.0'
8082
repos:
81-
- repo: https://github.com/Zac-HD/flake8-trio
83+
- repo: https://github.com/python-trio/flake8-async
8284
rev: 23.2.5
8385
hooks:
84-
- id: flake8-trio
85-
# args: [--enable=TRIO, --disable=TRIO9, --autofix=TRIO]
86+
- id: flake8-async
87+
# args: [--enable=ASYNC, --disable=ASYNC9, --autofix=ASYNC]
8688
```
8789

8890
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.
9092

9193

9294
Afterwards, run
9395
```sh
94-
pip install pre-commit flake8-trio
96+
pip install pre-commit flake8-async
9597
pre-commit run .
9698
```
9799
### install and run as standalone
98100
If inside a git repository, running without arguments will run it against all `*.py` files in the repository.
99101
```sh
100-
pip install flake8-trio
101-
flake8-trio
102+
pip install flake8-async
103+
flake8-async
102104
```
103105
#### with autofixes
104106
```sh
105-
flake8-trio --autofix=TRIO
107+
flake8-async --autofix=ASYNC
106108
```
107109
#### specifying source files
108110
```sh
109-
flake8-trio my_python_file.py
111+
flake8-async my_python_file.py
110112
```
111113
##### zsh-only
112114
```zsh
113-
flake8-trio **/*.py
115+
flake8-async **/*.py
114116
```
115117

116118
## Configuration
117119
[You can configure `flake8` with command-line options](https://flake8.pycqa.org/en/latest/user/configuration.html),
118120
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.
120122

121123
### `--enable`
122124
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
125127
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.
126128

127129
### `--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.
129131

130132
### `--error-on-autofix`
131133
Whether to also print an error message for autofixed errors.
@@ -134,7 +136,7 @@ Whether to also print an error message for autofixed errors.
134136
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].
135137

136138
### `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`.
138140

139141
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.
140142

@@ -158,14 +160,14 @@ startable-in-context-manager =
158160
myfun2,
159161
```
160162

161-
### `trio200-blocking-calls`
163+
### `async200-blocking-calls`
162164
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.
163165

164166
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.
165167

166168
Example:
167169
```ini
168-
trio200-blocking-calls =
170+
async200-blocking-calls =
169171
my_blocking_call -> async.alternative,
170172
module.block_call -> other_function_to_use,
171173
common_error_call -> alternative(). But sometimes you should use other_function(). Ask joe if you're unsure which one,

‎pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ignore = [
5454
"COM", # flake8-comma, handled by black
5555
"ANN", # annotations, handled by pyright/mypy
5656
"T20", # flake8-print
57-
"TID252", # relative imports from parent modules https://github.com/Zac-HD/flake8-trio/pull/196#discussion_r1200413372
57+
"TID252", # relative imports from parent modules https://github.com/python-trio/flake8-trio/pull/196#discussion_r1200413372
5858
"D101",
5959
"D102",
6060
"D103",

‎setup.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ def local_file(name: str) -> Path:
2020

2121

2222
setup(
23-
name="flake8-trio",
23+
name="flake8-async",
2424
version=__version__,
2525
author="Zac Hatfield-Dodds, John Litborn, and Contributors",
2626
author_email="zac@zhd.dev",
2727
packages=find_packages(include=["flake8_trio", "flake8_trio.*"]),
28-
url="https://github.com/Zac-HD/flake8-trio",
28+
url="https://github.com/python-trio/flake8-trio",
2929
license="MIT",
3030
description="A highly opinionated flake8 plugin for Trio-related problems.",
3131
zip_safe=False,
@@ -51,7 +51,7 @@ def local_file(name: str) -> Path:
5151
),
5252
long_description_content_type="text/markdown",
5353
entry_points={
54-
"flake8.extension": ["TRI = flake8_trio:Plugin"],
55-
"console_scripts": ["flake8-trio=flake8_trio:main"],
54+
"flake8.extension": ["ASY = flake8_trio:Plugin"],
55+
"console_scripts": ["flake8-async=flake8_trio:main"],
5656
},
5757
)

‎tests/test_changelog_and_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
"""Tests for flake8-trio package metadata."""
2+
"""Tests for flake8-async package metadata."""
33

44
from __future__ import annotations
55

‎tests/test_config_and_args.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def monkeypatch_argv(
4242
argv: list[Path | str] | None = None,
4343
) -> None:
4444
if argv is None:
45-
argv = [tmp_path / "flake8-trio", "./example.py"]
45+
argv = [tmp_path / "flake8-async", "./example.py"]
4646
monkeypatch.chdir(tmp_path)
4747
monkeypatch.setattr(sys, "argv", argv)
4848

@@ -51,7 +51,7 @@ def test_run_flake8_trio(tmp_path: Path):
5151
write_examplepy(tmp_path)
5252
res = subprocess.run(
5353
[
54-
"flake8-trio",
54+
"flake8-async",
5555
"./example.py",
5656
],
5757
cwd=tmp_path,
@@ -100,7 +100,7 @@ def test_run_in_git_repo(tmp_path: Path):
100100
subprocess.run(["git", "add", "example.py"], cwd=tmp_path, check=True)
101101
res = subprocess.run(
102102
[
103-
"flake8-trio",
103+
"flake8-async",
104104
],
105105
cwd=tmp_path,
106106
capture_output=True,
@@ -114,7 +114,7 @@ def test_run_in_git_repo(tmp_path: Path):
114114
def test_run_no_git_repo(
115115
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
116116
):
117-
monkeypatch_argv(monkeypatch, tmp_path, [tmp_path / "flake8-trio"])
117+
monkeypatch_argv(monkeypatch, tmp_path, [tmp_path / "flake8-async"])
118118
assert main() == 1
119119
out, err = capsys.readouterr()
120120
assert err == "Doesn't seem to be a git repo; pass filenames to format.\n"
@@ -128,7 +128,7 @@ def test_run_100_autofix(
128128
monkeypatch_argv(
129129
monkeypatch,
130130
tmp_path,
131-
[tmp_path / "flake8-trio", "--autofix=TRIO", "./example.py"],
131+
[tmp_path / "flake8-async", "--autofix=TRIO", "./example.py"],
132132
)
133133
assert main() == 1
134134

@@ -268,7 +268,7 @@ def test_enable(
268268
):
269269
write_examplepy(tmp_path)
270270

271-
argv: list[Path | str] = [tmp_path / "flake8-trio", "./example.py"]
271+
argv: list[Path | str] = [tmp_path / "flake8-async", "./example.py"]
272272
monkeypatch_argv(monkeypatch, tmp_path, argv)
273273

274274
def _helper(*args: str, error: bool = False, autofix: bool = False) -> None:
@@ -363,7 +363,7 @@ def test_disable_noqa_cst(
363363
monkeypatch_argv(
364364
monkeypatch,
365365
tmp_path,
366-
[tmp_path / "flake8-trio", "./example.py", "--disable-noqa"],
366+
[tmp_path / "flake8-async", "./example.py", "--disable-noqa"],
367367
)
368368
assert main() == 1
369369
out, err = capsys.readouterr()
@@ -382,7 +382,7 @@ def test_disable_noqa_ast(
382382
monkeypatch_argv(
383383
monkeypatch,
384384
tmp_path,
385-
[tmp_path / "flake8-trio", "./example.py", "--disable-noqa"],
385+
[tmp_path / "flake8-async", "./example.py", "--disable-noqa"],
386386
)
387387
assert main() == 1
388388
out, err = capsys.readouterr()

‎tests/test_flake8_trio.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def test_noerror_on_sync_code(test: str, path: Path):
438438

439439

440440
def initialize_options(plugin: Plugin, args: list[str] | None = None):
441-
parser = ArgumentParser(prog="flake8-trio")
441+
parser = ArgumentParser(prog="flake8-async")
442442
Plugin.add_options(parser)
443443
Plugin.parse_options(parser.parse_args(args))
444444

‎tests/test_messages_documented.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
"""Tests for flake8-trio package metadata."""
2+
"""Tests for flake8-async package metadata."""
33

44
from __future__ import annotations
55

0 commit comments

Comments
 (0)
Please sign in to comment.