diff --git a/codeflash/models/models.py b/codeflash/models/models.py index 70267c067..da1f3bfb3 100644 --- a/codeflash/models/models.py +++ b/codeflash/models/models.py @@ -331,11 +331,12 @@ def file_to_path(self) -> dict[str, str]: dict[str, str]: Mapping from file path (as string) to code. """ - if "file_to_path" in self._cache: + try: return self._cache["file_to_path"] - result = {str(code_string.file_path): code_string.code for code_string in self.code_strings} - self._cache["file_to_path"] = result - return result + except KeyError: + result = {str(code_string.file_path): code_string.code for code_string in self.code_strings} + self._cache["file_to_path"] = result + return result @staticmethod def parse_markdown_code(markdown_code: str, expected_language: str = "python") -> CodeStringsMarkdown: