Skip to content

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

Merged
charliermarsh merged 2 commits intoastral-sh:mainfrom
maltevesper:maltev/explicitWithBlockExceptions
Nov 21, 2023
Merged

[flake8-simplify] Omit select context managers from SIM117#8801
charliermarsh merged 2 commits intoastral-sh:mainfrom
maltevesper:maltev/explicitWithBlockExceptions

Conversation

@maltevesper
Copy link
Copy Markdown
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.

@github-actions
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
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