Skip to content
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 flake8_async ASYNC102 await in finally or cancelled #14370

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from

Conversation

altendky
Copy link

@altendky altendky commented Nov 15, 2024

Summary

When working with async cleanup activities it is important to be aware of shielding the cleanup from cancellation.

https://anyio.readthedocs.io/en/stable/cancellation.html#shielding

This rule looks for unshielded awaits in relevant cleanup paths such as exception handling and finally blocks. It walks the AST looking for awaits but prunes when it finds shielding context managers.

Test Plan

Draft For:

  • review TODOs
  • consider if this is the ruff implementation of https://flake8-async.readthedocs.io/en/latest/rules.html#async102 (at a glance the answer seems to be yes)
  • explicitly test async for and async with
  • review # noqa: ASYNC102 - fixthis which are mostly around direct assignment to the .shield attribute
  • revisit linter message, it's just shield it! right now
  • don't trigger on anyio and trio.aclose_forcefully()
  • review all panics and either implement or handle by having no output
  • handle .__aexit__()
  • require a timeout deadline

Copy link
Contributor

github-actions bot commented Nov 15, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@altendky altendky changed the title very preliminary unshielded await rule somewhat preliminary unshielded await rule Nov 18, 2024
@altendky altendky changed the title somewhat preliminary unshielded await rule somewhat preliminary unshielded async rule Nov 18, 2024
@altendky altendky changed the title somewhat preliminary unshielded async rule implement flake8_async ASYNC102 await in finally or cancelled Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant