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

[flake8-simplify] Omit select context managers from SIM117 #8801

Merged

Conversation

maltevesper
Copy link
Contributor

Semantically it makes sense to put certain contextmanagers into separate with statements. Currently asyncio.timeout and its relatives in anyio and trio are exempt from SIM117.

Closes #8606

Summary

Exempt asyncio.timeout and related functions from SIM117 (Collapse with statements where possible).
See #8606 for more.

Test Plan

Extended the insta tests.

Copy link
Contributor

github-actions bot commented Nov 21, 2023

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Semantically it makes sense to put certain contextmanagers
into separate with statements. Currently asyncio.timeout
and its relatives in anyio and trio are exempt from SIM117.

Closes astral-sh#8606
@maltevesper maltevesper force-pushed the maltev/explicitWithBlockExceptions branch from 6fb0bf9 to bcb447c Compare November 21, 2023 08:57
@maltevesper
Copy link
Contributor Author

I have not figured out how to make ruff work if the context manager is assigned to a variable.

x = asyncio.timeout(1)
async with x:
     async with A():
          ...

A quick poke around revealed that x is a binding, but I did not see how to extract type information for x, given that ruff is a linter/formatter and not a typechecker I assume this functionality is currently not included.
Should I bee mistaken, this PR would need fixing up.

Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label Nov 21, 2023
@charliermarsh charliermarsh changed the title Omit select context managers from SIM117 (#8606) [flake8-simplify] Omit select context managers from SIM117 Nov 21, 2023
@charliermarsh charliermarsh enabled auto-merge (squash) November 21, 2023 11:50
@charliermarsh charliermarsh merged commit 6fb6478 into astral-sh:main Nov 21, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Omit asyncio.timeout from SIM117
2 participants