Skip to content

ASYNC103 for sync functions #447

@A5rocks

Description

@A5rocks

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    rule improvementImprovement for currently existing rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions