Skip to content

Commit 0ae2d9f

Browse files
authored
Merge pull request #59 from jakkdl/105_await_nursery_start
fixes #56
2 parents a900cff + 748b9f0 commit 0ae2d9f

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

CHANGELOG.md

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

4+
## 22.11.2
5+
- TRIO105 now also checks that you `await`ed `nursery.start()`.
6+
47
## 22.11.1
58
- TRIO102 is no longer skipped in (async) context managers, since it's not a missing-checkpoint warning.
69

flake8_trio.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from flake8.options.manager import OptionManager
3030

3131
# CalVer: YY.month.patch, e.g. first release of July 2022 == "22.7.1"
32-
__version__ = "22.11.1"
32+
__version__ = "22.11.2"
3333

3434

3535
Error_codes = {
@@ -785,7 +785,7 @@ def iter_guaranteed_once(iterable: ast.expr) -> bool:
785785
return False
786786

787787

788-
trio_async_functions = (
788+
trio_async_funcs = (
789789
"aclose_forcefully",
790790
"open_file",
791791
"open_ssl_over_tcp_listeners",
@@ -806,6 +806,7 @@ def iter_guaranteed_once(iterable: ast.expr) -> bool:
806806
class Visitor105(Flake8TrioVisitor):
807807
def __init__(self, *args: Any, **kwargs: Any):
808808
super().__init__(*args, **kwargs)
809+
# keep a node stack so we can check whether calls are awaited
809810
self.node_stack: List[ast.AST] = []
810811

811812
def visit(self, node: ast.AST):
@@ -817,8 +818,10 @@ def visit_Call(self, node: ast.Call):
817818
if (
818819
isinstance(node.func, ast.Attribute)
819820
and isinstance(node.func.value, ast.Name)
820-
and node.func.value.id == "trio"
821-
and node.func.attr in trio_async_functions
821+
and (
822+
(node.func.value.id == "trio" and node.func.attr in trio_async_funcs)
823+
or (node.func.value.id == "nursery" and node.func.attr == "start")
824+
)
822825
and (
823826
len(self.node_stack) < 2
824827
or not isinstance(self.node_stack[-2], ast.Await)

tests/trio105.py

+9
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ async def foo():
4848
# it isn't supported
4949
k = trio.open_file() # error: 8, "open_file"
5050
await k
51+
52+
# issue #56
53+
nursery = trio.open_nursery()
54+
await nursery.start()
55+
await nursery.start_foo()
56+
57+
nursery.start() # error: 4, "start"
58+
nursery.start_soon()
59+
nursery.start_foo()

0 commit comments

Comments
 (0)