no-unsafe-tempfile-factories¶
Require tempfile context managers instead of unmanaged mkstemp or mkdtemp calls.
Message¶
Use tempfile context managers instead of mkstemp or mkdtemp.
Settings¶
| Setting | Description | Type | Default |
|---|---|---|---|
| excluded_path_parts | — | list | ['tests', 'benchmarks'] |
Valid examples¶
import tempfile
with tempfile.TemporaryDirectory() as path:
use(path)
Show more
from tempfile import NamedTemporaryFile
with NamedTemporaryFile() as file:
use(file.name)
from tempfile import mkstemp
factory().mkstemp()
Invalid examples¶
import tempfile
fd, path = tempfile.mkstemp()
from tempfile import mkdtemp as make_temp_dir
path = make_temp_dir()