-
Notifications
You must be signed in to change notification settings - Fork 1.3k
inconsistent behavior regarding asyncio-dangling-task (RUF006) #16811
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
Comments
Thanks for the report! I think this corresponds to one of the known false negative test cases added in #9060, but I don't see a tracking issue for it. I'm not that familiar with these |
I think the reason ruff doesn't dedect 4 is because s.add could await its parameter in some form or another. This seems a case where type checking can find this isse easily but we'd have to encode a long list of known methods that don't accept tasks |
I'm pretty sure |
I think @MichaReiser was referring to a more general case, where it's hard to tell the type of class Awaiter:
async def add(self, task):
await task
s = Awaiter()
...
s.add(task) ruff could currently handle specific cases like |
@ntBre oops my bad. Yes I got you. |
Summary
I see an inconsistent behavior in detecting
RUF006
rule.Output for
# 1
and# 3
is:Ruff correctly detects
# 1
and correctly discards# 2
(it has a reference in global). Now if Ruff decides to detect# 3
as error then# 4
should also be detected as error. There is no difference in how the returned references are stored.If Ruff detects
# 3
due to the fact thatt2
is only referenced inside the contained coroutine(and creates a circular reference) then it's the same as# 4
. One of them inside a local variable and one of them inside aset
object. In this case it should only discards# 4
if theset
object is defined outside in a global namespace.I don't know what the correct decision is but I guess those should be treated equally.
I might have missed something here, I would be grateful if you correct me. Thanks.
Version
ruff==0.10.0 (shipped with VSCode Ruff extension version 2025.18.0)
The text was updated successfully, but these errors were encountered: