Skip to content

Commit 2c18afd

Browse files
github-actions[bot]KRRT7claude
committed
fix: simplify get_run_tmp_file caching to use hasattr pattern
Use hasattr/attribute-access pattern (consistent with original code) instead of getattr, removing redundant re-assignment and verbose comment. Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a23954a commit 2c18afd

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

codeflash/code_utils/code_utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,10 @@ def get_all_function_names(code: str) -> tuple[bool, list[str]]:
408408
def get_run_tmp_file(file_path: Path | str) -> Path:
409409
if isinstance(file_path, str):
410410
file_path = Path(file_path)
411-
# Cache both the TemporaryDirectory object (so it isn't garbage-collected)
412-
# and the Path to its name to avoid repeatedly constructing Path(tmpdir.name).
413-
tmp_path = getattr(get_run_tmp_file, "tmpdir_path", None)
414-
if tmp_path is None:
411+
if not hasattr(get_run_tmp_file, "tmpdir_path"):
415412
get_run_tmp_file.tmpdir = TemporaryDirectory(prefix="codeflash_")
416413
get_run_tmp_file.tmpdir_path = Path(get_run_tmp_file.tmpdir.name)
417-
tmp_path = get_run_tmp_file.tmpdir_path
418-
return tmp_path / file_path
414+
return get_run_tmp_file.tmpdir_path / file_path
419415

420416

421417
def path_belongs_to_site_packages(file_path: Path) -> bool:

0 commit comments

Comments
 (0)