summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Hollas <daniel.hollas@bristol.ac.uk>2024-09-01 14:44:48 (GMT)
committerGitHub <noreply@github.com>2024-09-01 14:44:48 (GMT)
commit2304774465f3faddd8102d729ae6d3ca7e9cff49 (patch)
tree5d4ac55ce629751c4573b358e8fb9fb86aa06b2e
parent42a818912bdb367c4ec2b7d58c18db35f55ebe3b (diff)
downloadcpython-2304774465f3faddd8102d729ae6d3ca7e9cff49.zip
cpython-2304774465f3faddd8102d729ae6d3ca7e9cff49.tar.gz
cpython-2304774465f3faddd8102d729ae6d3ca7e9cff49.tar.bz2
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 <1324225+hugovk@users.noreply.github.com>
-rw-r--r--Lib/pathlib/_local.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/pathlib/_local.py b/Lib/pathlib/_local.py
index 674c98e..51abe58 100644
--- a/Lib/pathlib/_local.py
+++ b/Lib/pathlib/_local.py
@@ -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):
"""