Skip to content

Commit ebe7e97

Browse files
authored
async102 & async120 no longer requires cancelscope to have a timeout (#380)
1 parent 93913ef commit ebe7e97

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

docs/changelog.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ Changelog
44

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

7-
FUTURE
7+
25.5.2
88
======
9+
- :ref:`ASYNC102 <async102>` and :ref:`ASYNC120 <async120>` no longer requires cancel scopes to have a timeout. `(issue #272) <https://github.com/python-trio/flake8-async/issues/272>`_
910
- Add :ref:`ASYNC400 <async400>` except-star-invalid-attribute.
1011

1112
25.5.1
@@ -19,7 +20,7 @@ FUTURE
1920
25.4.3
2021
======
2122
- :ref:`ASYNC100 <async100>` can now autofix ``with`` statements with multiple items.
22-
- Fixed a bug where multiple ``with`` items would not interact, leading to ASYNC100 and ASYNC9xx false alarms. https://github.com/python-trio/flake8-async/issues/156
23+
- Fixed a bug where multiple ``with`` items would not interact, leading to ASYNC100 and ASYNC9xx false alarms. `(issue #367) <https://github.com/python-trio/flake8-async/issues/367>`_
2324

2425
25.4.2
2526
======
@@ -159,7 +160,7 @@ FUTURE
159160

160161
24.3.5
161162
======
162-
- ASYNC102 (no await inside finally or critical except) no longer raises warnings for calls to ``aclose()`` on objects in trio/anyio code. See https://github.com/python-trio/flake8-async/issues/156
163+
- ASYNC102 (no await inside finally or critical except) no longer raises warnings for calls to ``aclose()`` on objects in trio/anyio code. See `(issue #156) <https://github.com/python-trio/flake8-async/issues/156>`_
163164

164165
24.3.4
165166
======

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/async102.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ async def foo():
100100
try:
101101
pass
102102
finally:
103+
# it's now fine to have a shield and no timeout
103104
with trio.CancelScope(shield=True):
104-
await foo() # error: 12, Statement("try/finally", lineno-4)
105+
await foo()
105106
try:
106107
pass
107108
finally:

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)