diff --git a/python/promplate/prompt/utils.py b/python/promplate/prompt/utils.py index 92f9da9..e0e548b 100644 --- a/python/promplate/prompt/utils.py +++ b/python/promplate/prompt/utils.py @@ -146,7 +146,10 @@ def add_linecache(filename: str, source_getter: Callable[[], str]): def save_tempfile(filename: str, source: str, auto_deletion: bool): - from tempfile import mkdtemp + from tempfile import gettempdir, mkdtemp + + for i in Path(gettempdir()).glob(f"promplate-*/{filename}"): + i.unlink() file = Path(mkdtemp(prefix="promplate-")) / filename file.write_text(source) diff --git a/python/tests/test_template.py b/python/tests/test_template.py index 5152609..5953435 100644 --- a/python/tests/test_template.py +++ b/python/tests/test_template.py @@ -416,3 +416,12 @@ def test_error_handling(): t.render() except NameError: assert "__append__(a)" in format_exc() + + +def test_error_handling_namesake(): + with raises(ValueError, match="123"): + Template("{# raise ValueError(123) #}").render() + try: + Template("{# raise TypeError(123) #}").render() + except TypeError: + assert "ValueError" not in format_exc()