https://github.com/python/cpython/commit/655fc8a0fce3396fc1af3f7bc8f5c94ca8ec377d commit: 655fc8a0fce3396fc1af3f7bc8f5c94ca8ec377d branch: main author: Barney Gale <[email protected]> committer: barneygale <[email protected]> date: 2025-02-16T17:08:55Z summary:
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 Python 3.8, where `functools.cache()` is unavailable. files: M Lib/pathlib/_abc.py diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py index a9de8d6eb3c4c7..501f852059010f 100644 --- a/Lib/pathlib/_abc.py +++ b/Lib/pathlib/_abc.py @@ -11,18 +11,12 @@ WritablePath. """ -import functools from abc import ABC, abstractmethod from glob import _PathGlobber, _no_recurse_symlinks from pathlib import PurePath, Path from pathlib._os import magic_open, CopyReader, CopyWriter [email protected] -def _is_case_sensitive(parser): - return parser.normcase('Aa') == 'Aa' - - def _explode_path(path): """ 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): if not isinstance(pattern, JoinablePath): pattern = self.with_segments(pattern) if case_sensitive is None: - case_sensitive = _is_case_sensitive(self.parser) + case_sensitive = self.parser.normcase('Aa') == 'Aa' globber = _PathGlobber(pattern.parser.sep, case_sensitive, recursive=True) match = globber.compile(str(pattern)) return match(str(self)) is not None @@ -297,13 +291,12 @@ def glob(self, pattern, *, case_sensitive=None, recurse_symlinks=True): anchor, parts = _explode_path(pattern) if anchor: raise NotImplementedError("Non-relative patterns are unsupported") + case_sensitive_default = self.parser.normcase('Aa') == 'Aa' if case_sensitive is None: - case_sensitive = _is_case_sensitive(self.parser) - case_pedantic = False - elif case_sensitive == _is_case_sensitive(self.parser): + case_sensitive = case_sensitive_default case_pedantic = False else: - case_pedantic = True + case_pedantic = case_sensitive_default != case_sensitive recursive = True if recurse_symlinks else _no_recurse_symlinks globber = _PathGlobber(self.parser.sep, case_sensitive, case_pedantic, recursive) select = globber.selector(parts) _______________________________________________ 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]
