From: Daniel Hollas Date: Sun, 1 Sep 2024 14:44:48 +0000 (+0100) Subject: gh-118761: Speedup pathlib import by deferring shutil (#123520) X-Git-Tag: v3.14.0a1~624 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2304774465f3faddd8102d729ae6d3ca7e9cff49;p=thirdparty%2FPython%2Fcpython.git 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> --- diff --git a/Lib/pathlib/_local.py b/Lib/pathlib/_local.py index 674c98e1b305..51abe58410bc 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): """