https://github.com/python/cpython/commit/2304774465f3faddd8102d729ae6d3ca7e9cff49 commit: 2304774465f3faddd8102d729ae6d3ca7e9cff49 branch: main author: Daniel Hollas <[email protected]> committer: barneygale <[email protected]> date: 2024-09-01T15:44:48+01:00 summary:
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]> files: M Lib/pathlib/_local.py diff --git a/Lib/pathlib/_local.py b/Lib/pathlib/_local.py index 674c98e1b3050e..51abe58410bc7c 100644 --- a/Lib/pathlib/_local.py +++ b/Lib/pathlib/_local.py @@ -3,7 +3,6 @@ import operator import os import posixpath -import shutil import sys from glob import _StringGlobber from itertools import chain @@ -824,7 +823,10 @@ def rmdir(self): """ 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): """ _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
