From 844db19c581f4b3ac215810a66ad72e041551a54 Mon Sep 17 00:00:00 2001 From: HansBug Date: Fri, 27 Oct 2023 12:33:21 +0800 Subject: [PATCH] dev(hansbug): add safe protection --- hbutils/system/filesystem/tempfile.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hbutils/system/filesystem/tempfile.py b/hbutils/system/filesystem/tempfile.py index 2ac27653fd5..d555199f5c1 100644 --- a/hbutils/system/filesystem/tempfile.py +++ b/hbutils/system/filesystem/tempfile.py @@ -6,10 +6,14 @@ import platform import shutil import tempfile -import types import warnings import weakref +try: + from types import GenericAlias +except (ImportError, ModuleNotFoundError): + GenericAlias = None + __all__ = [ 'TemporaryDirectory', ] @@ -90,7 +94,8 @@ def cleanup(self): if self._finalizer.detach() or os.path.exists(self.name): self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors) - __class_getitem__ = classmethod(types.GenericAlias) + if GenericAlias is not None: + __class_getitem__ = classmethod(GenericAlias) else: class TemporaryDirectory(object):