python-trio / flake8-async

Highly opinionated linter for Trio code
https://flake8-async.readthedocs.io
MIT License
17 stars 2 forks source link

Handle critical exceptions in anyio #122

Closed jakkdl closed 1 year ago

jakkdl commented 1 year ago

Matters w/r/t TRIO102, 103 and 104.

flake8-trio currently always just looks for trio.Cancelled, but https://github.com/Zac-HD/flake8-trio/pull/120#discussion_r1095001688

Unfortunately anyio has a slightly different API here; see anyio.get_cancelled_exc_class(). That's important because you can have both trio and asyncio in the same program (ugh, but sometimes the least-bad option!).

Also add another error code for assigning the result of anyio.get_cancelled_exc_class() to a variable. That can be caught if within the same file with our rudimentary type tracking, but not if done across files and imported. So the plugin should likely track assignments for cases where single-backend is used and the error code gets disabled.

We probably also want to lint for "no assigning that result because it breaks our linter, as well as multi-backend programs".