From 179697f47b017f36197ff8e3fd58a00d5b1fe5a6 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 6 Jun 2026 01:47:15 +0000 Subject: [PATCH] perf: use context manager to explicitly close file descriptor Co-authored-by: savvides <1580637+savvides@users.noreply.github.com> --- bin/idstack-learnings-search | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/bin/idstack-learnings-search b/bin/idstack-learnings-search index 94cc40f..e6cbbe1 100755 --- a/bin/idstack-learnings-search +++ b/bin/idstack-learnings-search @@ -49,20 +49,21 @@ matches = [] for src in sources: is_global = 'global' in src try: - for line in open(src): - try: - d = json.loads(line) - if type_filter and d.get('type') != type_filter: - continue - if keyword: - insight = (d.get('insight', '') + ' ' + d.get('key', '')).lower() - if keyword not in insight: + with open(src) as f: + for line in f: + try: + d = json.loads(line) + if type_filter and d.get('type') != type_filter: continue - if is_global: - d['_source'] = 'global' - matches.append(json.dumps(d)) - except Exception: - pass + if keyword: + insight = (d.get('insight', '') + ' ' + d.get('key', '')).lower() + if keyword not in insight: + continue + if is_global: + d['_source'] = 'global' + matches.append(json.dumps(d)) + except Exception: + pass except Exception: pass