Skip to content

Commit 2304774

Browse files
danielhollasblurb-it[bot]hugovk
authored
gh-118761: Speedup pathlib import by deferring shutil (#123520)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 42a8189 commit 2304774

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Lib/pathlib/_local.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import operator
44
import os
55
import posixpath
6-
import shutil
76
import sys
87
from glob import _StringGlobber
98
from itertools import chain
@@ -824,7 +823,10 @@ def rmdir(self):
824823
"""
825824
os.rmdir(self)
826825

827-
_rmtree = shutil.rmtree
826+
def _rmtree(self):
827+
# Lazy import to improve module import time
828+
import shutil
829+
shutil.rmtree(self)
828830

829831
def rename(self, target):
830832
"""

0 commit comments

Comments
 (0)