From 9df127b4f96ea05b5752dadbb9e5452187f9f0ac Mon Sep 17 00:00:00 2001 From: 28ananthaprakash <36426881+28ananthaprakash@users.noreply.github.com> Date: Sun, 23 Nov 2025 09:04:42 +0000 Subject: [PATCH 1/3] fix: refactor file reading in read_lookup_table_file for better resource management --- rasa/nlu/utils/pattern_utils.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/rasa/nlu/utils/pattern_utils.py b/rasa/nlu/utils/pattern_utils.py index 6dd1ac3f20e2..48a3f438f77d 100644 --- a/rasa/nlu/utils/pattern_utils.py +++ b/rasa/nlu/utils/pattern_utils.py @@ -77,21 +77,19 @@ def read_lookup_table_file(lookup_table_file: Text) -> List[Text]: Elements listed in the lookup table file. """ try: - f = open(lookup_table_file, "r", encoding=rasa.shared.utils.io.DEFAULT_ENCODING) + with open(lookup_table_file, "r", encoding=rasa.shared.utils.io.DEFAULT_ENCODING) as f: + elements_to_regex = [] + for line in f: + new_element = line.strip() + if new_element: + elements_to_regex.append(new_element) + return elements_to_regex except OSError: raise ValueError( f"Could not load lookup table {lookup_table_file}. " f"Please make sure you've provided the correct path." ) - elements_to_regex = [] - with f: - for line in f: - new_element = line.strip() - if new_element: - elements_to_regex.append(new_element) - return elements_to_regex - def _collect_regex_features( training_data: TrainingData, use_only_entities: bool = False From a2a0abdd7621e63f8508e0711f760acdff7e4c1b Mon Sep 17 00:00:00 2001 From: 28ananthaprakash <36426881+28ananthaprakash@users.noreply.github.com> Date: Sun, 23 Nov 2025 09:06:07 +0000 Subject: [PATCH 2/3] fix: improve temporary file handling --- tests/nlu/featurizers/test_convert_featurizer.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/nlu/featurizers/test_convert_featurizer.py b/tests/nlu/featurizers/test_convert_featurizer.py index 503cf9117118..008aee65b41b 100644 --- a/tests/nlu/featurizers/test_convert_featurizer.py +++ b/tests/nlu/featurizers/test_convert_featurizer.py @@ -290,10 +290,9 @@ def test_raise_wrong_model_file( tmp_path: Path, ): # create a dummy file - temp_file = os.path.join(tmp_path, "saved_model.pb") - f = open(temp_file, "wb") - f.close() - component_config = {FEATURIZER_CLASS_ALIAS: "alias", "model_url": temp_file} + temp_file = tmp_path / "saved_model.pb" + temp_file.touch() + component_config = {FEATURIZER_CLASS_ALIAS: "alias", "model_url": str(temp_file)} with pytest.raises(RasaException) as excinfo: _ = create_or_load_convert_featurizer(component_config) From a423e082b1fb38889b39c642c1fcfc12cd4879ed Mon Sep 17 00:00:00 2001 From: 28ananthaprakash <36426881+28ananthaprakash@users.noreply.github.com> Date: Sun, 23 Nov 2025 09:07:03 +0000 Subject: [PATCH 3/3] fix: improve file handling for better readability --- .github/scripts/mr_generate_summary.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/scripts/mr_generate_summary.py b/.github/scripts/mr_generate_summary.py index 4d4b4285b64e..f8f529d5f993 100644 --- a/.github/scripts/mr_generate_summary.py +++ b/.github/scripts/mr_generate_summary.py @@ -47,7 +47,8 @@ def combine_result( reports_paths = list(reports_dir.glob("*/report.json")) for report_path in reports_paths: - report_dict = json.load(open(report_path)) + with open(report_path) as f: + report_dict = json.load(f) data = combine_result(data, report_dict) summary_file = os.environ["SUMMARY_FILE"]