Skip to content

pathlib ABCs: remove caching of path parser case sensitivity #130194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2025
Merged
Changes from all commits
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
15 changes: 4 additions & 11 deletions Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


@functools.cache
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading