mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
GH-127381: pathlib ABCs: remove case_sensitive argument (#131024)
Remove the *case_sensitive* argument from `_JoinablePath.full_match()` and `_ReadablePath.glob()`. Using a non-native case sensitivity forces the use of "case-pedantic" globbing, where we `iterdir()` even for non-wildcard pattern segments. But it's hard to know when to enable this mode, as case-sensitivity can vary by directory, so `_PathParser.normcase()` doesn't always give the full picture. The `Path.glob()` implementation is forced to make an educated guess, but we can avoid the issue in the ABCs by dropping the *case_sensitive* argument. (I probably shouldn't have added these arguments in `PurePath` and `Path` in the first place!) Also drop support for `_ReadablePath.glob(recurse_symlinks=False)`, which makes recursive globbing much slower.
This commit is contained in:
parent
c3487c941d
commit
93fc3d34f9
4 changed files with 27 additions and 30 deletions
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from glob import _PathGlobber, _no_recurse_symlinks
|
||||
from glob import _PathGlobber
|
||||
from pathlib import PurePath, Path
|
||||
from pathlib._os import magic_open, ensure_distinct_paths, copy_file
|
||||
from typing import Optional, Protocol, runtime_checkable
|
||||
|
|
@ -216,15 +216,14 @@ def parents(self):
|
|||
parent = split(path)[0]
|
||||
return tuple(parents)
|
||||
|
||||
def full_match(self, pattern, *, case_sensitive=None):
|
||||
def full_match(self, pattern):
|
||||
"""
|
||||
Return True if this path matches the given glob-style pattern. The
|
||||
pattern is matched against the entire path.
|
||||
"""
|
||||
if not hasattr(pattern, 'with_segments'):
|
||||
pattern = self.with_segments(pattern)
|
||||
if case_sensitive is None:
|
||||
case_sensitive = self.parser.normcase('Aa') == 'Aa'
|
||||
case_sensitive = self.parser.normcase('Aa') == 'Aa'
|
||||
globber = _PathGlobber(pattern.parser.sep, case_sensitive, recursive=True)
|
||||
match = globber.compile(str(pattern), altsep=pattern.parser.altsep)
|
||||
return match(str(self)) is not None
|
||||
|
|
@ -279,7 +278,7 @@ def iterdir(self):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def glob(self, pattern, *, case_sensitive=None, recurse_symlinks=True):
|
||||
def glob(self, pattern, *, recurse_symlinks=True):
|
||||
"""Iterate over this subtree and yield all existing files (of any
|
||||
kind, including directories) matching the given relative pattern.
|
||||
"""
|
||||
|
|
@ -288,14 +287,10 @@ 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 = case_sensitive_default
|
||||
case_pedantic = False
|
||||
else:
|
||||
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)
|
||||
elif not recurse_symlinks:
|
||||
raise NotImplementedError("recurse_symlinks=False is unsupported")
|
||||
case_sensitive = self.parser.normcase('Aa') == 'Aa'
|
||||
globber = _PathGlobber(self.parser.sep, case_sensitive, recursive=True)
|
||||
select = globber.selector(parts)
|
||||
return select(self.joinpath(''))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue