python-trio / flake8-async

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

Add TRIO232: blocking sync call on file objects #104

Closed jakkdl closed 1 year ago

jakkdl commented 1 year ago

A first draft at tracking types for file/path/httpx/etc and warning on sync calls. Except this one just does it for open() and the varios io.* types it can return as a start. This and others that build on top of it should finish off #58

Branched from on top of #103 - but you can just view the latest commit to see the contents of this one.

Zac-HD commented 1 year ago

Approach seems promising, agree that list[whatever] isn't worth handling but whatever|None probably is (if easy!). I look forward to seeing where this goes after rebasing 😁

jakkdl commented 1 year ago

Rebased on top of main (which wasn't trivial since it was forked from an outdated #103 that was later amended - fun stuff!). Will now continue working on it~

jakkdl commented 1 year ago

I'll refactor it in a different PR as I write the next object sync checker, as this one should work well as a standalone. Ready to merge!

Zac-HD commented 1 year ago

For the future refactored version, one annoying (to lint, it's fortunately rare) pattern is defining a httpx.Client() as a global variable...

jakkdl commented 1 year ago

For the future refactored version, one annoying (to lint, it's fortunately rare) pattern is defining a httpx.Client() as a global variable...

oh and it should work fine with global variables as long as they're defined in the same file. Will add tests to show that.

I'll make a PR just with these two fixes + another pattern I just realized will be useful:

async def type_assign():
    f: TextIOWrapper = ...
    f.read()