Skip to content

Commit 219c6d3

Browse files
authored
async110 now also warns if looping .lowlevel.checkpoint() (#221)
* async110 now also warns if looping .lowlevel.checkpoint() * bump __version__
1 parent 8702a80 commit 219c6d3

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22
*[CalVer, YY.month.patch](https://calver.org/)*
33

4+
## 24.3.4
5+
- ASYNC110 (don't loop sleep) now also warns if looping `[trio/anyio].lowlevel.checkpoint()`
6+
47
## 24.3.3
58
- Add ASYNC251: `time.sleep()` in async method.
69

flake8_async/__init__.py

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

3838

3939
# CalVer: YY.month.patch, e.g. first release of July 2022 == "22.7.1"
40-
__version__ = "24.3.3"
40+
__version__ = "24.3.4"
4141

4242

4343
# taken from https://github.com/Zac-HD/shed

flake8_async/visitors/visitors.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,19 @@ def visit_While(self, node: ast.While):
6565
len(node.body) == 1
6666
and isinstance(node.body[0], ast.Expr)
6767
and isinstance(node.body[0].value, ast.Await)
68-
and get_matching_call(node.body[0].value.value, "sleep", "sleep_until")
68+
and (
69+
get_matching_call(node.body[0].value.value, "sleep", "sleep_until")
70+
or (
71+
# get_matching_call doesn't (currently) support checking for trio.x.y
72+
isinstance(call := node.body[0].value.value, ast.Call)
73+
and isinstance(call.func, ast.Attribute)
74+
and call.func.attr == "checkpoint"
75+
and isinstance(call.func.value, ast.Attribute)
76+
and call.func.value.attr == "lowlevel"
77+
and isinstance(call.func.value.value, ast.Name)
78+
and call.func.value.value.id in ("trio", "anyio")
79+
)
80+
)
6981
):
7082
self.error(node, self.library_str)
7183

tests/eval_files/async110.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,8 @@ async def blah():
6969

7070
while await trio.sleep():
7171
...
72+
73+
# also error when looping .lowlevel.checkpoint, which is equivalent to .sleep(0)
74+
# see https://github.com/python-trio/flake8-async/issues/201
75+
while ...: # ASYNC110: 4, "trio"
76+
await trio.lowlevel.checkpoint()

0 commit comments

Comments
 (0)