Avoid unused async when context manager includes TaskGroup#12605
Avoid unused async when context manager includes TaskGroup#12605charliermarsh merged 1 commit intomainfrom
TaskGroup#12605Conversation
|
| .semantic() | ||
| .resolve_qualified_name(call.func.as_ref()) | ||
| .is_some_and(|qualified_name| { | ||
| matches!(qualified_name.segments(), ["asyncio", "TaskGroup"]) |
There was a problem hiding this comment.
Shouldn't it hold for any async context manager? I don't think there is something unique about asyncio.TaskGroup.
If the async with is explicitly nested then ruff doesn't trigger the error. So perhaps the fix should be to make
async with asyncio.timeout(), foo():
...be treated the same as
async with asyncio.timeout():
async with foo():
...According to the Language Reference they are semantically equivalent (this is for with, the async with ref seems to have an omission here):
I also checked async for and it's detected correctly.
There was a problem hiding this comment.
I think you're right.
There was a problem hiding this comment.
Interested in changing it? :) We might need to accommodate cases like async with asyncio.timeout(), asyncio.timeout(), I guess those should still trigger even if weird.
… (`ASYNC100`) (#12643) ## Summary Please see #12605 (comment) for a description of the issue. They way I fixed it is to get the *last* timeout item in the `with`, and if it's an `async with` and there are items after it, then don't trigger the lint. ## Test Plan Updated the fixture with some more cases.

Summary
Closes #12354.