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"] 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 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)