Skip to content

Commit d454ebc

Browse files
committed
async120 no longer requires cancelscope to have a timeout
1 parent 00d63c3 commit d454ebc

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Changelog
44

55
`CalVer, YY.month.patch <https://calver.org/>`_
66

7+
25.5.2
8+
======
9+
- :ref:`ASYNC120 <async120>` no longer requires cancel scopes to have a timeout. https://github.com/python-trio/flake8-async/issues/272
10+
711
25.5.1
812
======
913
- Fixed :ref:`ASYNC113 <async113>` false alarms if the ``start_soon`` calls are in a nursery cm that was closed before the yield point.

docs/usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ adding the following to your ``.pre-commit-config.yaml``:
3333
minimum_pre_commit_version: '2.9.0'
3434
repos:
3535
- repo: https://github.com/python-trio/flake8-async
36-
rev: 25.5.1
36+
rev: 25.5.2
3737
hooks:
3838
- id: flake8-async
3939
# args: ["--enable=ASYNC100,ASYNC112", "--disable=", "--autofix=ASYNC"]

flake8_async/__init__.py

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

3939

4040
# CalVer: YY.month.patch, e.g. first release of July 2022 == "22.7.1"
41-
__version__ = "25.5.1"
41+
__version__ = "25.5.2"
4242

4343

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

flake8_async/visitors/visitor102_120.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ def __init__(self, node: ast.Call, funcname: str):
4040
self.funcname = funcname
4141
self.variable_name: str | None = None
4242
self.shielded: bool = False
43-
self.has_timeout: bool = True
44-
45-
# scope.shielded is assigned to in visit_Assign
46-
47-
if self.funcname == "CancelScope":
48-
self.has_timeout = False
49-
for kw in node.keywords:
50-
# note: sets to True even if timeout is explicitly set to inf
51-
if kw.arg == "deadline":
52-
self.has_timeout = True
5343

5444
# trio 0.27 adds shield parameter to all scope helpers
5545
if self.funcname in cancel_scope_names:
@@ -79,7 +69,7 @@ def async_call_checker(
7969
self, node: ast.Await | ast.AsyncFor | ast.AsyncWith
8070
) -> None:
8171
if self._critical_scope is not None and not any(
82-
cm.has_timeout and cm.shielded for cm in self._trio_context_managers
72+
cm.shielded for cm in self._trio_context_managers
8373
):
8474
# non-critical exception handlers have the statement name set to "except"
8575
if self._critical_scope.name == "except":

tests/eval_files/async120.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,13 @@ async def foobar():
121121
await foo()
122122

123123
raise
124+
125+
126+
# shielded but no timeout no longer triggers async120
127+
# https://github.com/python-trio/flake8-async/issues/272
128+
async def foo_shield_no_timeout():
129+
try:
130+
...
131+
finally:
132+
with trio.CancelScope(shield=True):
133+
await foo()

0 commit comments

Comments
 (0)