From 3afea883951d73806e28ab4e06bd7f7942629eed Mon Sep 17 00:00:00 2001 From: Ivan Protsyuk Date: Wed, 9 Nov 2022 13:20:46 +0000 Subject: [PATCH] Close smarts file handle after reading This PR fixes the following warning: ``` dimorphite_dl/dimorphite_dl.py:718: ResourceWarning: unclosed file <_io.TextIOWrapper name='dimorphite_dl/site_substructures.smarts' mode='r' encoding='UTF-8'> for l in open(site_structures_file, "r") ResourceWarning: Enable tracemalloc to get the object allocation traceback ``` --- dimorphite_dl.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/dimorphite_dl.py b/dimorphite_dl.py index 73719b1..2dadad1 100644 --- a/dimorphite_dl.py +++ b/dimorphite_dl.py @@ -713,11 +713,8 @@ def load_substructre_smarts_file(): pwd = os.path.dirname(os.path.realpath(__file__)) site_structures_file = "{}/{}".format(pwd, "site_substructures.smarts") - lines = [ - l - for l in open(site_structures_file, "r") - if l.strip() != "" and not l.startswith("#") - ] + with open(site_structures_file, "r") as f: + lines = [l for l in f if l.strip() != "" and not l.startswith("#")] return lines