Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Changelog

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

FUTURE
25.5.2
======
- :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>`_
- Add :ref:`ASYNC400 <async400>` except-star-invalid-attribute.

25.5.1
Expand All @@ -19,7 +20,7 @@ FUTURE
25.4.3
======
- :ref:`ASYNC100 <async100>` can now autofix ``with`` statements with multiple items.
- 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
- 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>`_

25.4.2
======
Expand Down Expand Up @@ -159,7 +160,7 @@ FUTURE

24.3.5
======
- 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
- 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>`_

24.3.4
======
Expand Down
2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ adding the following to your ``.pre-commit-config.yaml``:
minimum_pre_commit_version: '2.9.0'
repos:
- repo: https://github.com/python-trio/flake8-async
rev: 25.5.1
rev: 25.5.2
hooks:
- id: flake8-async
# args: ["--enable=ASYNC100,ASYNC112", "--disable=", "--autofix=ASYNC"]
Expand Down
2 changes: 1 addition & 1 deletion flake8_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


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


# taken from https://github.com/Zac-HD/shed
Expand Down
12 changes: 1 addition & 11 deletions flake8_async/visitors/visitor102_120.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ def __init__(self, node: ast.Call, funcname: str):
self.funcname = funcname
self.variable_name: str | None = None
self.shielded: bool = False
self.has_timeout: bool = True

# scope.shielded is assigned to in visit_Assign

if self.funcname == "CancelScope":
self.has_timeout = False
for kw in node.keywords:
# note: sets to True even if timeout is explicitly set to inf
if kw.arg == "deadline":
self.has_timeout = True

# trio 0.27 adds shield parameter to all scope helpers
if self.funcname in cancel_scope_names:
Expand Down Expand Up @@ -79,7 +69,7 @@ def async_call_checker(
self, node: ast.Await | ast.AsyncFor | ast.AsyncWith
) -> None:
if self._critical_scope is not None and not any(
cm.has_timeout and cm.shielded for cm in self._trio_context_managers
cm.shielded for cm in self._trio_context_managers
):
# non-critical exception handlers have the statement name set to "except"
if self._critical_scope.name == "except":
Expand Down
3 changes: 2 additions & 1 deletion tests/eval_files/async102.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ async def foo():
try:
pass
finally:
# it's now fine to have a shield and no timeout
with trio.CancelScope(shield=True):
await foo() # error: 12, Statement("try/finally", lineno-4)
await foo()
try:
pass
finally:
Expand Down
10 changes: 10 additions & 0 deletions tests/eval_files/async120.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,13 @@ async def foobar():
await foo()

raise


# shielded but no timeout no longer triggers async120
# https://github.com/python-trio/flake8-async/issues/272
async def foo_shield_no_timeout():
try:
...
finally:
with trio.CancelScope(shield=True):
await foo()
Loading