Skip to content

Commit 35dc640

Browse files
committed
Address issue #310 points 1 and 4
1. Document using ruff's `lint.external` setting so that `# noqa: ASYNC...` comments survive when both ruff and flake8-async are in use. 4. Apply the `self.novisit = True` fix proposed in #307 at the end of `Visitor102.visit_Try`. The previous code happened to work because the internal `visit_nodes` calls left `self.novisit` True on exit, but relying on that is fragile; making it explicit matches the pattern used elsewhere and documents the intent.
1 parent 808a157 commit 35dc640

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Unreleased
99
- Autofix for :ref:`ASYNC910 <async910>` / :ref:`ASYNC911 <async911>` no longer inserts checkpoints inside ``except`` clauses (which would trigger :ref:`ASYNC120 <async120>`); instead the checkpoint is added at the top of the function or of the enclosing loop. `(issue #403) <https://github.com/python-trio/flake8-async/issues/403>`_
1010
- :ref:`ASYNC910 <async910>` and :ref:`ASYNC911 <async911>` now accept ``__aenter__`` / ``__aexit__`` methods when the partner method provides the checkpoint, or when only one of the two is defined on a class that inherits from another class (charitably assuming the partner is inherited and contains a checkpoint). `(issue #441) <https://github.com/python-trio/flake8-async/issues/441>`_
1111
- :ref:`ASYNC300 <async300>` no longer triggers when the result of ``asyncio.create_task()`` is returned from a function. `(issue #398) <https://github.com/python-trio/flake8-async/issues/398>`_
12+
- Document using ruff's ``lint.external`` setting to preserve ``# noqa: ASYNC...`` comments when running ruff alongside flake8-async. `(issue #310) <https://github.com/python-trio/flake8-async/issues/310>`_
1213

1314
25.7.1
1415
======

docs/usage.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ Run through ruff
9191

9292
They currently only support a small subset of the ``flake8-async`` rules though, see https://github.com/astral-sh/ruff/issues/8451 for current status and https://docs.astral.sh/ruff/rules/#flake8-async-async for documentation.
9393

94+
Using both ruff and flake8-async
95+
--------------------------------
96+
97+
Ruff will by default strip any ``# noqa`` comments for codes it does not know about, which breaks suppressions for ``ASYNC`` codes that ruff hasn't reimplemented. You can tell ruff to preserve them by listing ``ASYNC`` under `lint.external <https://docs.astral.sh/ruff/settings/#lint_external>`_ in your ruff config:
98+
99+
.. code-block:: toml
100+
101+
# pyproject.toml
102+
[tool.ruff.lint]
103+
external = ["ASYNC"]
104+
105+
With that in place you can continue to run ``flake8-async`` (either via ``flake8``, pre-commit, or as a standalone) alongside ``ruff`` without losing ``# noqa: ASYNC...`` comments.
106+
94107
*************
95108
Configuration
96109
*************

flake8_async/visitors/visitor102_120.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ def visit_Try(self, node: ast.Try | ast.TryStar): # type: ignore[name-defined]
153153
self._critical_scope = Statement("try/finally", node.lineno, node.col_offset)
154154
self.visit_nodes(node.finalbody)
155155

156+
# we've manually visited the Try fields above; stop the runner from doing
157+
# it a second time via generic_visit.
158+
self.novisit = True
159+
156160
visit_TryStar = visit_Try
157161

158162
def visit_ExceptHandler(self, node: ast.ExceptHandler):

0 commit comments

Comments
 (0)