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

Consider suggesting using tempfile classes as context managers #7313

Open
NeilGirdhar opened this issue Sep 12, 2023 · 2 comments · Fixed by #12959
Open

Consider suggesting using tempfile classes as context managers #7313

NeilGirdhar opened this issue Sep 12, 2023 · 2 comments · Fixed by #12959
Labels
rule Implementing or modifying a lint rule
Milestone

Comments

@NeilGirdhar
Copy link

Just as in:

f = Path.open('x')  # SIM115 Use context handler for opening files
f.close()

Ruff nudges the user to use context managers, Ruff should do the same for:

from tempfile import NamedTemporaryFile
f = NamedTemporaryFile()  # Should nudge SIM115
f.close()

and similarly for the other classes in tempfile.

@NeilGirdhar NeilGirdhar changed the title Consider suggesting using context managers with tempfile classes Consider suggesting using tempfile classes as context managers Sep 12, 2023
@zanieb zanieb added the rule Implementing or modifying a lint rule label Sep 12, 2023
@zanieb
Copy link
Member

zanieb commented Sep 12, 2023

Sounds good to me!

@AlexWaygood
Copy link
Member

AlexWaygood commented Aug 27, 2024

Reopening the issue for now so we remember to stabilise the new behaviour as part of Ruff 0.7

@AlexWaygood AlexWaygood reopened this Aug 27, 2024
@AlexWaygood AlexWaygood added this to the v0.7 milestone Aug 27, 2024
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
3 participants