Skip to content

Consider suggesting using tempfile classes as context managers  #7313

@NeilGirdhar

Description

@NeilGirdhar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions