From 0cf0d68cf20bf154667042c5240f460cbf9a81b1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Langa?= Date: Mon, 28 Oct 2019 17:42:46 +0100 Subject: [PATCH 1/1] Explicitly close .gitignore during processing --- black.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/black.py b/black.py index b3699d5..1c42f59 100644 --- a/black.py +++ b/black.py @@ -3469,10 +3469,11 @@ def get_future_imports(node: Node) -> Set[str]: def get_gitignore(root: Path) -> PathSpec: """ Return a PathSpec matching gitignore content if present.""" gitignore = root / ".gitignore" - if not gitignore.is_file(): - return PathSpec.from_lines("gitwildmatch", []) - else: - return PathSpec.from_lines("gitwildmatch", gitignore.open()) + lines: List[str] = [] + if gitignore.is_file(): + with gitignore.open() as gf: + lines = gf.readlines() + return PathSpec.from_lines("gitwildmatch", lines) def gen_python_files_in_dir( -- 2.39.5