From dd3f138830f352dac59eea6683d2c9490070dabe Mon Sep 17 00:00:00 2001 From: Paul O'Leary McCann Date: Thu, 16 Feb 2023 19:08:55 +0900 Subject: [PATCH] Use tempfile.TemporaryDirectory (#12285) --- spacy/util.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spacy/util.py b/spacy/util.py index e2ca0e6a4..2ce2e5e0f 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -1028,12 +1028,11 @@ def make_tempdir() -> Generator[Path, None, None]: YIELDS (Path): The path of the temp directory. """ - d = Path(tempfile.mkdtemp()) - yield d try: - shutil.rmtree(str(d)) + with tempfile.TemporaryDirectory() as td: + yield Path(td) except PermissionError as e: - warnings.warn(Warnings.W091.format(dir=d, msg=e)) + warnings.warn(Warnings.W091.format(dir=td, msg=e)) def is_cwd(path: Union[Path, str]) -> bool: