Skip to content

Commit fe751bc

Browse files
authored
standardize to [a/b] (#212)
Change all instances of [a|b} to [a/b] in documentation, etc.
1 parent 5c6879a commit fe751bc

File tree

7 files changed

+24
-23
lines changed

7 files changed

+24
-23
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pip install flake8-async
2323
```
2424

2525
## List of warnings
26-
- **ASYNC100**: A `with [trio|anyio].fail_after(...):` or `with [trio|anyio].move_on_after(...):`
26+
- **ASYNC100**: A `with [trio/anyio].fail_after(...):` or `with [trio/anyio].move_on_after(...):`
2727
context does not contain any `await` statements. This makes it pointless, as
2828
the timeout can only be triggered by a checkpoint.
2929
- **ASYNC101**: `yield` inside a trio/anyio nursery or cancel scope is only safe when implementing a context manager - otherwise, it breaks exception handling.
@@ -33,13 +33,13 @@ pip install flake8-async
3333
- **ASYNC105**: Calling a trio async function without immediately `await`ing it. This is only supported with trio functions, but you can get similar functionality with a type-checker.
3434
- **ASYNC106**: `trio`/`anyio`/`asyncio` must be imported with `import trio`/`import anyio`/`import asyncio` for the linter to work.
3535
- **ASYNC109**: Async function definition with a `timeout` parameter - use `[trio/anyio].[fail/move_on]_[after/at]` instead.
36-
- **ASYNC110**: `while <condition>: await [trio/anyio].sleep()` should be replaced by a `[trio|anyio].Event`.
36+
- **ASYNC110**: `while <condition>: await [trio/anyio].sleep()` should be replaced by a `[trio/anyio].Event`.
3737
- **ASYNC111**: Variable, from context manager opened inside nursery, passed to `start[_soon]` might be invalidly accessed while in use, due to context manager closing before the nursery. This is usually a bug, and nurseries should generally be the inner-most context manager.
3838
- **ASYNC112**: Nursery body with only a call to `nursery.start[_soon]` and not passing itself as a parameter can be replaced with a regular function call.
3939
- **ASYNC113**: Using `nursery.start_soon` in `__aenter__` doesn't wait for the task to begin. Consider replacing with `nursery.start`.
4040
- **ASYNC114**: Startable function (i.e. has a `task_status` keyword parameter) not in `--startable-in-context-manager` parameter list, please add it so ASYNC113 can catch errors when using it.
41-
- **ASYNC115**: Replace `[trio|anyio].sleep(0)` with the more suggestive `[trio|anyio].lowlevel.checkpoint()`.
42-
- **ASYNC116**: `[trio|anyio].sleep()` with >24 hour interval should usually be `[trio|anyio].sleep_forever()`.
41+
- **ASYNC115**: Replace `[trio/anyio].sleep(0)` with the more suggestive `[trio/anyio].lowlevel.checkpoint()`.
42+
- **ASYNC116**: `[trio/anyio].sleep()` with >24 hour interval should usually be `[trio/anyio].sleep_forever()`.
4343
- **ASYNC118**: Don't assign the value of `anyio.get_cancelled_exc_class()` to a variable, since that breaks linter checks and multi-backend programs.
4444

4545
### Warnings for blocking sync calls in async functions
@@ -48,13 +48,13 @@ Note: 22X, 23X and 24X has not had asyncio-specific suggestions written.
4848
- **ASYNC210**: Sync HTTP call in async function, use `httpx.AsyncClient`. This and the other ASYNC21x checks look for usage of `urllib3` and `httpx.Client`, and recommend using `httpx.AsyncClient` as that's the largest http client supporting anyio/trio.
4949
- **ASYNC211**: Likely sync HTTP call in async function, use `httpx.AsyncClient`. Looks for `urllib3` method calls on pool objects, but only matching on the method signature and not the object.
5050
- **ASYNC212**: Blocking sync HTTP call on httpx object, use httpx.AsyncClient.
51-
- **ASYNC220**: Sync process call in async function, use `await nursery.start([trio|anyio].run_process, ...)`.
52-
- **ASYNC221**: Sync process call in async function, use `await [trio|anyio].run_process(...)`.
53-
- **ASYNC222**: Sync `os.*` call in async function, wrap in `await [trio|anyio].to_thread.run_sync()`.
54-
- **ASYNC230**: Sync IO call in async function, use `[trio|anyio].open_file(...)`.
55-
- **ASYNC231**: Sync IO call in async function, use `[trio|anyio].wrap_file(...)`.
56-
- **ASYNC232**: Blocking sync call on file object, wrap the file object in `[trio|anyio].wrap_file()` to get an async file object.
57-
- **ASYNC240**: Avoid using `os.path` in async functions, prefer using `[trio|anyio].Path` objects.
51+
- **ASYNC220**: Sync process call in async function, use `await nursery.start([trio/anyio].run_process, ...)`.
52+
- **ASYNC221**: Sync process call in async function, use `await [trio/anyio].run_process(...)`.
53+
- **ASYNC222**: Sync `os.*` call in async function, wrap in `await [trio/anyio].to_thread.run_sync()`.
54+
- **ASYNC230**: Sync IO call in async function, use `[trio/anyio].open_file(...)`.
55+
- **ASYNC231**: Sync IO call in async function, use `[trio/anyio].wrap_file(...)`.
56+
- **ASYNC232**: Blocking sync call on file object, wrap the file object in `[trio/anyio].wrap_file()` to get an async file object.
57+
- **ASYNC240**: Avoid using `os.path` in async functions, prefer using `[trio/anyio].Path` objects.
5858

5959
### Warnings disabled by default
6060
- **ASYNC900**: Async generator without `@asynccontextmanager` not allowed. You might want to enable this on a codebase since async generators are inherently unsafe and cleanup logic might not be performed. See https://github.com/python-trio/flake8-async/issues/211 and https://discuss.python.org/t/using-exceptiongroup-at-anthropic-experience-report/20888/6 for discussion.
@@ -134,7 +134,7 @@ Comma-separated list of error-codes to enable autofixing for if implemented. Req
134134
Whether to also print an error message for autofixed errors.
135135

136136
### `--anyio`
137-
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].
137+
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].
138138

139139
### `no-checkpoint-warning-decorators`
140140
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`.

flake8_async/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ def add_options(option_manager: OptionManager | ArgumentParser):
293293
required=False,
294294
default=False,
295295
help=(
296-
"Change the default library to be anyio instead of trio."
297-
" If trio is imported it will assume both are available and print"
298-
" suggestions with [anyio|trio]."
296+
"Change the default library for suggestions to be anyio instead of trio."
297+
" If asyncio/trio is imported it will assume that is also available and"
298+
" print suggestions with [asyncio/anyio/trio]."
299299
),
300300
)
301301
add_argument(
@@ -306,9 +306,10 @@ def add_options(option_manager: OptionManager | ArgumentParser):
306306
required=False,
307307
default=False,
308308
help=(
309-
"Change the default library to be asyncio instead of trio."
309+
"Change the default library for suggestions to be asyncio instead of"
310+
" trio."
310311
" If anyio/trio is imported it will assume that is also available and"
311-
" print suggestions with [asyncio|anyio/trio]."
312+
" print suggestions with [asyncio/anyio/trio]."
312313
),
313314
)
314315

flake8_async/visitors/flake8asyncvisitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def library(self) -> tuple[str, ...]:
148148
def library_str(self) -> str:
149149
if len(self.library) == 1:
150150
return self.library[0]
151-
return "[" + "|".join(self.library) + "]"
151+
return "[" + "/".join(self.library) + "]"
152152

153153
def add_library(self, name: str) -> None:
154154
if name not in self.__state.library:

flake8_async/visitors/visitor103_104.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# TODO: ugly
2828
for a, b in (("anyio", "trio"), ("anyio", "asyncio"), ("asyncio", "trio")):
2929
_suggestion_dict[(a, b)] = (
30-
"[" + "|".join((_suggestion_dict[(a,)], _suggestion_dict[(b,)])) + "]"
30+
"[" + "/".join((_suggestion_dict[(a,)], _suggestion_dict[(b,)])) + "]"
3131
)
3232
_suggestion_dict[
3333
(
@@ -110,7 +110,7 @@ def visit_ExceptHandler(self, node: ast.ExceptHandler):
110110

111111
# Don't save the state of cancelled_caught, that's handled in Try and would
112112
# reset it between each except
113-
# Don't need to reset the values of unraised_[break|continue] since that's handled
113+
# Don't need to reset the values of unraised_[break/continue] since that's handled
114114
# by visit_For, but need to save the state of them to not mess up loops we're
115115
# nested inside
116116
self.save_state(

tests/eval_files/anyio_trio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010

1111

1212
async def foo():
13-
subprocess.Popen() # ASYNC220: 4, 'subprocess.Popen', "[anyio|trio]"
13+
subprocess.Popen() # ASYNC220: 4, 'subprocess.Popen', "[anyio/trio]"

tests/eval_files/trio_anyio.py

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

88

99
async def foo():
10-
subprocess.Popen() # ASYNC220: 4, 'subprocess.Popen', "[trio|anyio]"
10+
subprocess.Popen() # ASYNC220: 4, 'subprocess.Popen', "[trio/anyio]"

tests/test_config_and_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_anyio_from_config(tmp_path: Path, capsys: pytest.CaptureFixture[str]):
172172

173173
err_msg = Visitor22X.error_codes["ASYNC220"].format(
174174
"subprocess.Popen",
175-
"[anyio|trio]",
175+
"[anyio/trio]",
176176
)
177177
err_file = Path(__file__).parent / "eval_files" / "anyio_trio.py"
178178

0 commit comments

Comments
 (0)