Visitar URL original
gh-104484: Add parameter @case_sensitive to pathlib.PurePath.match() function by thirumurugan-git · Pull Request #104565 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update document
  • Loading branch information
thirumurugan-git authored and thirumurugan-ka-15679 committed May 18, 2023
commit 466abc2e819c73cf1c8994917d0bb38f69082d1f
9 changes: 0 additions & 9 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -576,15 +576,6 @@ Pure paths provide the following methods and properties:
>>> PureWindowsPath('b.py').match('*.PY')
True

By default, or when the *case_sensitive* keyword-only argument is set to
``None``, this method matches paths using platform-specific casing rules:
typically, case-sensitive on POSIX, and case-insensitive on Windows::

>>> PurePosixPath('b.py').match('*.PY')
False
>>> PureWindowsPath('b.py').match('*.PY')
True

Set *case_sensitive* to ``True`` or ``False`` to override this behaviour.

.. versionadded:: 3.12
Expand Down
9 changes: 3 additions & 6 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ def match(self, path_pattern, *, case_sensitive=None):
"""
Return True if this path matches the given pattern.
"""
if case_sensitive is None:
case_sensitive = _is_case_sensitive(self._flavour)
pat = self.with_segments(path_pattern)
if not pat.parts:
raise ValueError("empty pattern")
Expand All @@ -700,13 +702,8 @@ def match(self, path_pattern, *, case_sensitive=None):
return False
elif len(pat_parts) > len(parts):
return False
# Generate regex flag based on |case_sensitive| parameter.
if case_sensitive is None:
case_sensitive = _is_case_sensitive(self._flavour)
flags = re.NOFLAG if case_sensitive else re.IGNORECASE

for part, pat in zip(reversed(parts), reversed(pat_parts)):
match = _compile_pattern(pat, flags)
match = _compile_pattern(pat, case_sensitive)
if not match(part):
return False
return True
Expand Down