python-trio / flake8-async

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

Add support for anyio.get_cancelled_exc_class() in TRIO102, 103 and 104. #127

Closed jakkdl closed 1 year ago

jakkdl commented 1 year ago

Fixes #122

rewrote critical_except a bit as I updated it, in large part because I personally failed to read the old version of the code :innocent: Fix #106 for TRIO102 (#109 only fixed TRIO103 & TRIO104) Thanks to #125 it was quite smooth to add a different suggestion for TRIO103 when anyio is the primary library. As I started to write a assert_correct_message test helper I realized I had pretty bad code duplication, so checking of column, message and args are now all handled in assert_correct_attribute. Improved how ignore_column is handled in anyio tests. A slew of tests being moved around and modified and stuff so the necessary eval_files are handled with trio/anyio as appropriate. And some additional ones for #106+TRIO102

jakkdl commented 1 year ago

Added a separate error message when both are available.

But I'm unsure how to handle TRIO103 when both are imported, should bare excepts require that both have been handled in that case? See the new trio103_both_imported.py which tests for such cases.

Zac-HD commented 1 year ago

I'm unsure how to handle TRIO103 when both are imported, should bare excepts require that both have been handled in that case?

I think in this case it's safe to just catch anyio.get_cancelled_exc_class(), because if you're actually running Trio code that will return trio.Cancelled.

jakkdl commented 1 year ago

I'm unsure how to handle TRIO103 when both are imported, should bare excepts require that both have been handled in that case?

I think in this case it's safe to just catch anyio.get_cancelled_exc_class(), because if you're actually running Trio code that will return trio.Cancelled.

If you're running all three async libraries, and anyio's current backend is asyncio, and in the try: statement stuff is ran that could either raise trio.Cancelled or anyio.get_cancelled_exc_class(), it might bork? But that seems weird enough that I think not raising false alarms is more important.

jakkdl commented 1 year ago

addressed nitpicks and rebased on top of main to ensure coverage.