From 1fd659ceb13c4d56c82d1cbc8e5f92cd67030682 Mon Sep 17 00:00:00 2001 From: toanmap Date: Mon, 30 Mar 2026 22:10:40 +0700 Subject: [PATCH] refactor: unclosed file handle for readme.md (#620) The `README.md` file is opened using `open('README.md', 'r')` but is never explicitly closed. This can lead to resource leaks, especially in long-running processes or if the script were to be extended to open many files. While Python's garbage collector might eventually close it, it's not guaranteed and is considered bad practice. Affected files: ensure_sorted.py Signed-off-by: toanmap <174589430+maptoan@users.noreply.github.com> --- ensure_sorted.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ensure_sorted.py b/ensure_sorted.py index 700c321..50b6683 100755 --- a/ensure_sorted.py +++ b/ensure_sorted.py @@ -54,10 +54,10 @@ class Category: return self.__str__() def main(): - readme_file = open('README.md', 'r') # start of the Apps section APPS_LINE_START = '## – Apps –\n' - lines = readme_file.readlines() + with open('README.md', 'r') as readme_file: + lines = readme_file.readlines() index: int try: