python-trio / python-trio/flake8-async

ASYNC103 for sync functions

Open
#447 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

rule improvement
Dominant language
Python
Stars
26
Forks
10
PR merge metrics
No merged PRs in 30d

Description

I don't think sync functions can raise trio.Cancelled, but this is causing ASYNC103:

    def call(
        self,
        hookname: str,
        *args: object,
    ) -> None:
        # snip
        for instrument in list(self.data[hookname]):
            try:
                getattr(instrument, hookname)(*args)
            except BaseException:  # E
                self.remove_instrument(instrument)
                INSTRUMENT_LOGGER.exception(
                    "Exception raised when calling %r on instrument %r. "
                    "Instrument has been disabled.",
                    hookname,
                    instrument,
                )

Error message:

src/trio/_core/_instrumentation.py:110:20: ASYNC103 BaseException block with a code path that doesn't re-raise the error. Consider adding an `except trio.Cancelled: raise` before this exception handler.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing ASYNC103 against the sync call shown in src/trio/_core/_instrumentation.py and inspect how the rule distinguishes synchronous and asynchronous functions. Done means the false positive is no longer reported while the intended ASYNC103 cases still are; add or update the relevant regression test once its location is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.