-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement TRIO105 for anyio (library function must be awaited) #121
Comments
nursery calls have also been implemented in this since #56, that should probably be rewritten to use the new type-tracking functionality (Do we also want name-based tracking on top of that?), and anyio's version of that is Task Groups and https://anyio.readthedocs.io/en/stable/api.html#anyio.create_task_group |
Skimming through that issue, we only used name-based tracking at all because we thought type-based tracking wasn't worth the trouble. Since we have the latter now let's add that; but keep name-based checks for For |
This only matters if they're not typing the parameter list, if they do it's covered. While giving false positives on non-nursery objects named |
Hmm, we currently only match |
Ah yes, I was assuming I'll import over the type-tracking functionality used in 2xx, where types in parameter lists are picked up. |
Searching github, I get >7k code results for "task_group", and 18k for "taskgroup" in python code - and skimming the first few pages I find that e.g. Apache AirFlow has something called task groups, and bunch of random people implementing whatever they call task groups. Searching for So it's definitely a relatively common name for Stuff:tm:, so it ends up becoming a tradeoff between false positives vs checking untyped code where task groups are sent around as parameters or other complicated stuff. |
OK, let's just check based on types and the name "tg" then. Thanks for investigating! |
Related documentation things: we should have a tiny section listing deprecated
Note also that |
We do have TRIO117 for the deprecated MultiError, but that's a special case so a generic error code for deprecated library functions sounds good. |
Went through the anyio API: awaitable functionsI note that this is more comprehensive than we have for trio, where no submodule functions are checked.
awaitable methodsAre just way too many and messy to list manually, so would either runtime generate these - or write some fancy thing to generate a hard-coded list. Or a lot of them aren't useful, and relevant ones can be hand-picked. But checking for them would be somewhat doable with the type-tracking, and not just do
deprecated functions
stuff that shouldn't be awaitedhttps://github.com/agronholm/anyio/blob/5d9a476d6e3e6b6d7b1876fa18e70cd910d2e7e7/docs/migration.rst The transition from AnyIO 2 to 3 seems to have been ~1.5 years ago, but shouldn't be much effort to also check these. functions
methods
context managers
|
I'm inclined to leave out awaitable methods (except tg.start) as not high enough priority to be worth the trouble at the moment, and leave deprecated don't-await-this to the runtime system since they'll go away at some point without us. |
Sounds good, I'll leave those out for the time being and can consider revisiting them later. Any code for awaitable methods would of course be reusable for Trio methods, and don't-await-this could also be extended to check all non-async functions in trio/anyio. I'm a bit vary of matching the variable name of |
Ah, awaiting non-awaitable functions/methods is picked up by type checkers - which makes it somewhat redundant, though requires strict typing of return values. |
Let's leave this to typecheckers; illegal-await is also an immediate error at runtime and thus easier to debug than missing-await errors. |
Ooh, mypy 1.0.0 does give me
now when I write async with anyio.create_task_group() as bar:
bar.start(my_callable) # TRIO113: 8, anyio.TaskGroup.start And it catches all the awaitable library functions as well ... so there's maybe a decent case for skipping TRIO105 for anyio and just tell people to use mypy? (pyright does not give the warning, did not check other ones) I tried installing trio.typing and enabling it's plugin to see if it would catch the trio one as well - but it didn't. So should maybe spend some time figuring out what part of trio's magic breaks that check. |
Yeah, let's stick with the status quo then. Low priority, I'd like to work out why |
Coolies. I will push a PR with some modifications to type tracking and nurseries I implemented before I realized this, but otherwise revert most modifications. Oh nvm, pyright does have support for it - but since eval_files are in the exclude list it didn't say anything even when explicitly passed the file 😅 So this falls under "static typing improvements for Trio" in the TODO, I might do some more testing/looking around and then maybe open an issue / comment on some existing typing issue in trio. |
From #120 (comment)
I can probably compile it without too much issue, but let's have a separate issue & PR for it.
The text was updated successfully, but these errors were encountered: