python: Close opened files.

Fixes various instances of ‘ResourceWarning: unclosed file’ with
python -Wd.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-10-24 00:33:54 -07:00
committed by Tim Abbott
parent bb2db31f29
commit 31d0141a30
16 changed files with 156 additions and 134 deletions

View File

@@ -10,12 +10,13 @@ from typing import Iterable, List
def expand_reqs_helper(fpath: str) -> List[str]:
result = [] # type: List[str]
for line in open(fpath):
if line.strip().startswith(('#', '--hash')):
continue
dep = line.split(" \\", 1)[0].strip()
if dep:
result.append(dep)
with open(fpath) as f:
for line in f:
if line.strip().startswith(('#', '--hash')):
continue
dep = line.split(" \\", 1)[0].strip()
if dep:
result.append(dep)
return result
def expand_reqs(fpath: str) -> List[str]: