Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async110 now also warns if looping .lowlevel.checkpoint() #221

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
*[CalVer, YY.month.patch](https://calver.org/)*

## 24.3.4
- ASYNC110 (don't loop sleep) now also warns if looping `[trio/anyio].lowlevel.checkpoint()`

## 24.3.3
- Add ASYNC251: `time.sleep()` in async method.

Expand Down
2 changes: 1 addition & 1 deletion flake8_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


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


# taken from https://github.com/Zac-HD/shed
Expand Down
14 changes: 13 additions & 1 deletion flake8_async/visitors/visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,19 @@ def visit_While(self, node: ast.While):
len(node.body) == 1
and isinstance(node.body[0], ast.Expr)
and isinstance(node.body[0].value, ast.Await)
and get_matching_call(node.body[0].value.value, "sleep", "sleep_until")
and (
get_matching_call(node.body[0].value.value, "sleep", "sleep_until")
or (
# get_matching_call doesn't (currently) support checking for trio.x.y
isinstance(call := node.body[0].value.value, ast.Call)
and isinstance(call.func, ast.Attribute)
and call.func.attr == "checkpoint"
and isinstance(call.func.value, ast.Attribute)
and call.func.value.attr == "lowlevel"
and isinstance(call.func.value.value, ast.Name)
and call.func.value.value.id in ("trio", "anyio")
)
)
):
self.error(node, self.library_str)

Expand Down
5 changes: 5 additions & 0 deletions tests/eval_files/async110.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ async def blah():

while await trio.sleep():
...

# also error when looping .lowlevel.checkpoint, which is equivalent to .sleep(0)
# see https://github.com/python-trio/flake8-async/issues/201
while ...: # ASYNC110: 4, "trio"
await trio.lowlevel.checkpoint()
Loading