Skip to content

Commit

Permalink
Assign trio110
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Aug 5, 2022
1 parent 5bafeaa commit ea669fb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Future
- Added TRIO109: Async definitions should not have a `timeout` parameter. Use `trio.[fail/move_on]_[at/after]`
- Added TRIO301: `while <condition>: await trio.sleep()` should be replaced by a `trio.Event`.
- Added TRIO110: `while <condition>: await trio.sleep()` should be replaced by a `trio.Event`.

## 22.7.6
- Extend TRIO102 to also check inside `except BaseException` and `except trio.Cancelled`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ pip install flake8-trio
- **TRIO108**: Early return from async function must have at least one checkpoint on every code path before it, unless an exception is raised.
Checkpoints are `await`, `async with` `async for`.
- **TRIO109**: Async function definition with a `timeout` parameter - use `trio.[fail/move_on]_[after/at]` instead
- **TRIO301**: `while <condition>: await trio.sleep()` should be replaced by a `trio.Event`.
- **TRIO110**: `while <condition>: await trio.sleep()` should be replaced by a `trio.Event`.
8 changes: 4 additions & 4 deletions flake8_trio.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,17 @@ def check_109(self, args: ast.arguments):
self.error(TRIO109, arg.lineno, arg.col_offset)

def visit_While(self, node: ast.While):
self.check_for_301(node)
self.check_for_110(node)
self.generic_visit(node)

def check_for_301(self, node: ast.While):
def check_for_110(self, node: ast.While):
if (
len(node.body) == 1
and isinstance(node.body[0], ast.Expr)
and isinstance(node.body[0].value, ast.Await)
and get_trio_scope(node.body[0].value.value, "sleep", "sleep_until")
):
self.error(TRIO301, node.lineno, node.col_offset)
self.error(TRIO110, node.lineno, node.col_offset)


def critical_except(node: ast.ExceptHandler) -> Optional[Tuple[int, int, str]]:
Expand Down Expand Up @@ -653,4 +653,4 @@ def run(self) -> Iterable[Error]:
TRIO107 = "TRIO107: Async functions must have at least one checkpoint on every code path, unless an exception is raised"
TRIO108 = "TRIO108: Early return from async function must have at least one checkpoint on every code path before it."
TRIO109 = "TRIO109: Async function definition with a `timeout` parameter - use `trio.[fail/move_on]_[after/at]` instead"
TRIO301 = "TRIO301: `while <condition>: await trio.sleep()` should be replaced by a `trio.Event`."
TRIO110 = "TRIO110: `while <condition>: await trio.sleep()` should be replaced by a `trio.Event`."

0 comments on commit ea669fb

Please sign in to comment.