Skip to content

Commit 264b8d5

Browse files
optimize pathlib
1 parent fc54e72 commit 264b8d5

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Lib/pathlib.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import sys
99
import warnings
1010
from _collections_abc import Sequence
11-
from errno import EINVAL, ENOENT, ENOTDIR, EBADF, ELOOP
12-
from operator import attrgetter
11+
from errno import ENOENT, ENOTDIR, EBADF, ELOOP
1312
from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO
1413
from urllib.parse import quote_from_bytes as urlquote_from_bytes
1514

@@ -364,7 +363,7 @@ def group(self, path):
364363
#
365364
# Globbing helpers
366365
#
367-
366+
@functools.lru_cache
368367
def _make_selector(pattern_parts, flavour):
369368
pat = pattern_parts[0]
370369
child_parts = pattern_parts[1:]
@@ -378,9 +377,6 @@ def _make_selector(pattern_parts, flavour):
378377
cls = _PreciseSelector
379378
return cls(pat, child_parts, flavour)
380379

381-
if hasattr(functools, "lru_cache"):
382-
_make_selector = functools.lru_cache()(_make_selector)
383-
384380

385381
class _Selector:
386382
"""A selector matches a specific glob pattern part against the children
@@ -693,11 +689,15 @@ def __ge__(self, other):
693689
def __class_getitem__(cls, type):
694690
return cls
695691

696-
drive = property(attrgetter('_drv'),
697-
doc="""The drive prefix (letter or UNC path), if any.""")
692+
@property
693+
def drive(self):
694+
"""The drive prefix (letter or UNC path), if any."""
695+
return self._drv
698696

699-
root = property(attrgetter('_root'),
700-
doc="""The root of the path, if any.""")
697+
@property
698+
def root(self):
699+
"""The root of the path, if any."""
700+
return self._root
701701

702702
@property
703703
def anchor(self):

0 commit comments

Comments
 (0)