Skip to content

Commit b15d632

Browse files
committed
async102 not applicable to asyncio
1 parent aab418e commit b15d632

File tree

12 files changed

+19
-11
lines changed

12 files changed

+19
-11
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.7.1
8+
======
9+
- :ref:`ASYNC102 <async102>` no longer triggered for asyncio due to different cancellation semantics it uses.
10+
711
25.5.3
812
======
913
- :ref:`ASYNC115 <async115>` and :ref:`ASYNC116 <async116>` now also checks kwargs.

docs/rules.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ _`ASYNC101` : yield-in-cancel-scope
2424
_`ASYNC102` : await-in-finally-or-cancelled
2525
``await`` inside ``finally``, :ref:`cancelled-catching <cancelled>` ``except:``, or ``__aexit__`` must have shielded :ref:`cancel scope <cancel_scope>` with timeout.
2626
If not, the async call will immediately raise a new cancellation, suppressing any cancellation that was caught.
27+
Not applicable to asyncio due to edge-based cancellation semantics it uses as opposed to level-based used by trio and anyio.
2728
See :ref:`ASYNC120 <async120>` for the general case where other exceptions might get suppressed.
28-
This is currently not able to detect asyncio shields.
2929

3030
ASYNC103 : no-reraise-cancelled
3131
:ref:`cancelled`-catching exception that does not reraise the exception.

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.3
36+
rev: 25.7.1
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.3"
41+
__version__ = "25.7.1"
4242

4343

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

flake8_async/visitors/visitor102_120.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def async_call_checker(
7474
# non-critical exception handlers have the statement name set to "except"
7575
if self._critical_scope.name == "except":
7676
self._potential_120.append((node, self._critical_scope))
77-
else:
77+
# not applicable to asyncio due to different cancellation semantics it uses
78+
elif self.library != ("asyncio",):
7879
self.error(node, self._critical_scope, error_code="ASYNC102")
7980

8081
def visit_Raise(self, node: ast.Raise):
@@ -84,10 +85,7 @@ def visit_Raise(self, node: ast.Raise):
8485

8586
def is_safe_aclose_call(self, node: ast.Await) -> bool:
8687
return (
87-
# don't mark calls safe in asyncio-only files
88-
# a more defensive option would be `asyncio not in self.library`
89-
self.library != ("asyncio",)
90-
and isinstance(node.value, ast.Call)
88+
isinstance(node.value, ast.Call)
9189
# only known safe if no arguments
9290
and not node.value.args
9391
and not node.value.keywords

tests/eval_files/async102.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# type: ignore
22
# ARG --enable=ASYNC102,ASYNC120
3-
# NOASYNCIO # TODO: support asyncio shields
3+
# ASYNCIO_NO_ERROR # ASYNC102 not applicable to asyncio
44
from contextlib import asynccontextmanager
55

66
import trio

tests/eval_files/async102_aclose.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# ANYIO_NO_ERROR
88
# TRIO_NO_ERROR
99

10+
# ASYNCIO_NO_ERROR # ASYNC102 not applicable to asyncio
11+
1012
# See also async102_aclose_args.py - which makes sure trio/anyio raises errors if there
1113
# are arguments to aclose().
1214

tests/eval_files/async102_aclose_args.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# type: ignore
22

3+
# ASYNCIO_NO_ERROR # ASYNC102 not applicable to asyncio
4+
35
# trio/anyio should still raise errors if there's args
46
# asyncio will always raise errors
57

tests/eval_files/async102_anyio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# type: ignore
22
# NOTRIO
3-
# NOASYNCIO
3+
# ASYNCIO_NO_ERROR # ASYNC102 not applicable to asyncio
44
# BASE_LIBRARY anyio
55
# this test will raise the same errors with trio/asyncio, despite [trio|asyncio].get_cancelled_exc_class not existing
66
# marked not to run the tests though as error messages will only refer to anyio

tests/eval_files/async102_asyncio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# NOANYIO
33
# NOTRIO
44
# BASE_LIBRARY asyncio
5+
# ASYNCIO_NO_ERROR # ASYNC102 not applicable to asyncio
56
from contextlib import asynccontextmanager
67

78
import asyncio

0 commit comments

Comments
 (0)