Skip to content

Commit f0d631f

Browse files
committed
Improve import time of pathlib
1 parent fb8d8d9 commit f0d631f

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

Lib/pathlib/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
import posixpath
1313
import sys
1414
from errno import *
15-
from glob import _StringGlobber, _no_recurse_symlinks
1615
from itertools import chain
1716
from stat import (
1817
S_IMODE, S_ISDIR, S_ISREG, S_ISLNK, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO,
1918
)
2019
from _collections_abc import Sequence
20+
lazy import shutil
21+
lazy from glob import _StringGlobber, _no_recurse_symlinks
2122

2223
try:
2324
import pwd
@@ -1255,8 +1256,6 @@ def _delete(self):
12551256
if self.is_symlink() or self.is_junction():
12561257
self.unlink()
12571258
elif self.is_dir():
1258-
# Lazy import to improve module import time
1259-
import shutil
12601259
shutil.rmtree(self)
12611260
else:
12621261
self.unlink()

Lib/test/test_pathlib/test_pathlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_is_notimplemented(self):
8484
class LazyImportTest(unittest.TestCase):
8585
@cpython_only
8686
def test_lazy_import(self):
87-
import_helper.ensure_lazy_imports("pathlib", {"shutil"})
87+
import_helper.ensure_lazy_imports("pathlib", {"glob", "shutil"})
8888

8989

9090
#

0 commit comments

Comments
 (0)