]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118761: Speedup pathlib import by deferring shutil (#123520)
authorDaniel Hollas <daniel.hollas@bristol.ac.uk>
Sun, 1 Sep 2024 14:44:48 +0000 (15:44 +0100)
committerGitHub <noreply@github.com>
Sun, 1 Sep 2024 14:44:48 +0000 (15:44 +0100)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Lib/pathlib/_local.py

index 674c98e1b3050ea3f5540055fbd09ba059627612..51abe58410bc7c832e76bc68e0d5af0996c76835 100644 (file)
@@ -3,7 +3,6 @@ import ntpath
 import operator
 import os
 import posixpath
-import shutil
 import sys
 from glob import _StringGlobber
 from itertools import chain
@@ -824,7 +823,10 @@ class Path(PathBase, PurePath):
         """
         os.rmdir(self)
 
-    _rmtree = shutil.rmtree
+    def _rmtree(self):
+        # Lazy import to improve module import time
+        import shutil
+        shutil.rmtree(self)
 
     def rename(self, target):
         """