|  | 
| 14 | 14 | from glob import _PathGlobber, _no_recurse_symlinks | 
| 15 | 15 | from pathlib import PurePath, Path | 
| 16 | 16 | from pathlib._os import magic_open, ensure_distinct_paths, copy_file | 
| 17 |  | -from typing import Protocol, runtime_checkable | 
|  | 17 | +from typing import Optional, Protocol, runtime_checkable | 
| 18 | 18 | 
 | 
| 19 | 19 | 
 | 
| 20 | 20 | def _explode_path(path): | 
| @@ -44,6 +44,7 @@ class _PathParser(Protocol): | 
| 44 | 44 |     """ | 
| 45 | 45 | 
 | 
| 46 | 46 |     sep: str | 
|  | 47 | +    altsep: Optional[str] | 
| 47 | 48 |     def split(self, path: str) -> tuple[str, str]: ... | 
| 48 | 49 |     def splitext(self, path: str) -> tuple[str, str]: ... | 
| 49 | 50 |     def normcase(self, path: str) -> str: ... | 
| @@ -135,7 +136,9 @@ def with_name(self, name): | 
| 135 | 136 |         split = self.parser.split | 
| 136 | 137 |         if split(name)[0]: | 
| 137 | 138 |             raise ValueError(f"Invalid name {name!r}") | 
| 138 |  | -        return self.with_segments(split(str(self))[0], name) | 
|  | 139 | +        path = str(self) | 
|  | 140 | +        path = path.removesuffix(split(path)[1]) + name | 
|  | 141 | +        return self.with_segments(path) | 
| 139 | 142 | 
 | 
| 140 | 143 |     def with_stem(self, stem): | 
| 141 | 144 |         """Return a new path with the stem changed.""" | 
| @@ -223,7 +226,7 @@ def full_match(self, pattern, *, case_sensitive=None): | 
| 223 | 226 |         if case_sensitive is None: | 
| 224 | 227 |             case_sensitive = self.parser.normcase('Aa') == 'Aa' | 
| 225 | 228 |         globber = _PathGlobber(pattern.parser.sep, case_sensitive, recursive=True) | 
| 226 |  | -        match = globber.compile(str(pattern)) | 
|  | 229 | +        match = globber.compile(str(pattern), altsep=pattern.parser.altsep) | 
| 227 | 230 |         return match(str(self)) is not None | 
| 228 | 231 | 
 | 
| 229 | 232 | 
 | 
|  | 
0 commit comments