From 2d825943ac74a106d517e62bf9f70d674b8b04aa Mon Sep 17 00:00:00 2001 From: "Naelson Douglas C. Oliveira" Date: Thu, 28 Oct 2021 14:05:38 -0300 Subject: [PATCH] Don't leak an open file handle; fix Pyling R1732 (#584) **The problem** The code had a case of a manual file handler pitfall, where a resource stream is opened manually and never closed. This pitfall was detected using Pyling, which triggered a message of code R1732 with the content "Consider using 'with' for resource-allocating operations" **The solution** Used a 'with' block to automatically close the open stream on the file just after it is no longer needed --- build.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.py b/build.py index 478e5b414..c615bad61 100644 --- a/build.py +++ b/build.py @@ -572,7 +572,8 @@ def ttfautohint(path: str) -> None: # Step 1.5: Adding STAT tables in one go print ("[Cascadia Variable fonts] Fixing STAT tables") fontSTAT = [fontTools.ttLib.TTFont(f) for f in list(OUTPUT_TTF_DIR.glob("*.ttf"))] - config = yaml.load(open(INPUT_DIR/"stat.yaml"), Loader=yaml.SafeLoader) + with open(INPUT_DIR/"stat.yaml") as f: + config = yaml.load(f, Loader=yaml.SafeLoader) gen_stat_tables_from_config(config, fontSTAT) for font in fontSTAT: