Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit655fc8a

Browse files
authored
pathlib ABCs: remove caching of path parser case sensitivity (#130194)
Remove the caching `_is_case_sensitive()` function. The cache used to speed up `PurePath.[full_]match()` and `Path.[r]glob()`,but that's no longer the case - these methods use`self.parser is posixpath` to determine case sensitivity.This makes the `pathlib._abc` module a little easier to backport to Python3.8, where `functools.cache()` is unavailable.
1 parente7f00cd commit655fc8a

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

‎Lib/pathlib/_abc.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,12 @@
1111
WritablePath.
1212
"""
1313

14-
importfunctools
1514
fromabcimportABC,abstractmethod
1615
fromglobimport_PathGlobber,_no_recurse_symlinks
1716
frompathlibimportPurePath,Path
1817
frompathlib._osimportmagic_open,CopyReader,CopyWriter
1918

2019

21-
@functools.cache
22-
def_is_case_sensitive(parser):
23-
returnparser.normcase('Aa')=='Aa'
24-
25-
2620
def_explode_path(path):
2721
"""
2822
Split the path into a 2-tuple (anchor, parts), where *anchor* is the
@@ -201,7 +195,7 @@ def full_match(self, pattern, *, case_sensitive=None):
201195
ifnotisinstance(pattern,JoinablePath):
202196
pattern=self.with_segments(pattern)
203197
ifcase_sensitiveisNone:
204-
case_sensitive=_is_case_sensitive(self.parser)
198+
case_sensitive=self.parser.normcase('Aa')=='Aa'
205199
globber=_PathGlobber(pattern.parser.sep,case_sensitive,recursive=True)
206200
match=globber.compile(str(pattern))
207201
returnmatch(str(self))isnotNone
@@ -297,13 +291,12 @@ def glob(self, pattern, *, case_sensitive=None, recurse_symlinks=True):
297291
anchor,parts=_explode_path(pattern)
298292
ifanchor:
299293
raiseNotImplementedError("Non-relative patterns are unsupported")
294+
case_sensitive_default=self.parser.normcase('Aa')=='Aa'
300295
ifcase_sensitiveisNone:
301-
case_sensitive=_is_case_sensitive(self.parser)
302-
case_pedantic=False
303-
elifcase_sensitive==_is_case_sensitive(self.parser):
296+
case_sensitive=case_sensitive_default
304297
case_pedantic=False
305298
else:
306-
case_pedantic=True
299+
case_pedantic=case_sensitive_default!=case_sensitive
307300
recursive=Trueifrecurse_symlinkselse_no_recurse_symlinks
308301
globber=_PathGlobber(self.parser.sep,case_sensitive,case_pedantic,recursive)
309302
select=globber.selector(parts)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp