You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Match rules against canonical qualnames across all import styles
Previously the linter only recognised trio/anyio/asyncio-related calls when
they appeared exactly as `trio.open_nursery`, `anyio.create_task_group`, etc.
Aliased imports (`import trio as t`), `from` imports (`from trio import
open_nursery`), and aliased-from imports (`from trio import open_nursery as
on`) silently escaped detection.
This adds a pair of utility visitors (VisitorImportTracker / _cst) that
build a local-name -> canonical-dotted-qualname map, a pair of helpers
(resolve_canonical_ast / _cst) and base-class shortcut `canonical_name()`,
and threads an `imports=` keyword through the existing matcher helpers
(get_matching_call[_cst], fnmatch_qualified_name[_cst], with_has_call,
calls_any_of, critical_except). The tracker only records module-level
imports, so function-local imports don't leak into sibling scopes.
Existing visitors are updated to pass `self.imports` to those helpers, and
ASYNC105/ASYNC115/ASYNC118/ASYNC2xx/ASYNC300 etc. now match via canonical
qualname instead of the literal spelling. ASYNC106 was a workaround for
the old limitation; it's now disabled by default but left in place for
projects that still want to enforce the `import trio` style.
Closes#132.
https://claude.ai/code/session_018Hc9rcA31SnXcN8Ee5vVwH
* Tighten canonical-qualname code and comments
- Drop redundant canonical_name() docstrings.
- Simplify fnmatch_qualified_name[_cst] to build a candidate set inline.
- Fold the resolve_canonical_ast recursive arm into one-liners.
- Drop ASYNC21X's bespoke urllib3-import set -- consult the shared imports map.
- Collapse ASYNC22X's raw_name/canonical/func_name triplet into two locals.
- Simplify with_has_call's canonical fallback to a startswith + suffix check.
- Consolidate the CST scope-tracker's three visit/leave pairs into shared helpers.
- Rewrite the narrative "this change" comments as reader-facing rationale,
both in the code and in the eval-file annotations.
https://claude.ai/code/session_018Hc9rcA31SnXcN8Ee5vVwH
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Appease ruff and mypy
- Move resolve_canonical_ast/cst into a dedicated _canonical module so the
base-class methods can import them at the top level (PLC0415).
- Flatten nested isinstance chain in get_matching_call_cst (SIM102).
- Reformat the import-tracker example table so ruff stops flagging the
continuation line as commented-out code (ERA001).
- Inline the isinstance(ast.Call) check in critical_except so mypy's narrowing
kicks in (attr-defined on "expr").
- Drop the now-unused identifier_to_string import from visitor91x.
https://claude.ai/code/session_018Hc9rcA31SnXcN8Ee5vVwH
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add label to ASYNC106 docs so changelog cross-reference resolves
The changelog entry `:ref:`ASYNC106 <async106>`` targets a rule that didn't
have a Sphinx label, which made readthedocs fail with `undefined label:
'async106'` under `-W`.
https://claude.ai/code/session_018Hc9rcA31SnXcN8Ee5vVwH
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Copy file name to clipboardExpand all lines: docs/changelog.rst
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,8 @@ Changelog
6
6
7
7
Unreleased
8
8
==========
9
+
- Rules resolve function/class references via the canonical qualname, so checks fire regardless of import style (``import trio``, ``import trio as t``, ``from trio import open_nursery [as on]``, …). Only module-level imports are tracked. `(issue #132) <https://github.com/python-trio/flake8-async/issues/132>`_
10
+
- :ref:`ASYNC106 <async106>` is now disabled by default; re-enable it to enforce the ``import trio`` style.
9
11
- 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>`_
10
12
- :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>`_
11
13
- :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>`_
0 commit comments