﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32821	Use a with statement when using os.scandir()	Chris Jerdonek	nobody	"I noticed that Django doesn't use a `with` statement (or call `close()`) when it uses `os.scandir()`, which is what the [https://docs.python.org/3/library/os.html#os.scandir.close Python docs advise as of 3.6]. Here is [https://github.com/django/django/blob/ecf8af79355c8daa67722bd0de946b351f7f613d/django/core/files/storage.py#L324-L328 one example in the code]. There appear to be 7 uses of `os.scandir()` in all, with 5 in test code.

Usage with the `with` statement looks like this:

{{{#!python
with os.scandir(path) as entries:
    for entry in entries:
        ...
}}}

Not using a `with` statement or closing the iterator can cause a `ResourceWarning`, e.g. when an exception is raised. Indeed, this is how I first noticed this issue.
"	Cleanup/optimization	new	Uncategorized	dev	Normal				Unreviewed	1	0	0	0	0	0
