Skip to content
Merged
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
Handle classes that subclass PathBase and os.PathLike but not Path.
  • Loading branch information
barneygale committed Jun 4, 2024
commit 0aceea237fe3ad79bd00fa53da1939b0bf320b9f
12 changes: 9 additions & 3 deletions Lib/pathlib/_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,17 @@ def copy(self, target, follow_symlinks=True):
symlink and follow_symlinks is false, a symlink will be created at the
target.
"""
if isinstance(target, PathBase) and not isinstance(target, Path):
return PathBase.copy(self, target, follow_symlinks=follow_symlinks)
try:
target = os.fspath(target)
except TypeError:
if isinstance(target, PathBase):
# Target is an instance of PathBase but not os.PathLike.
# Use generic implementation from PathBase.
return PathBase.copy(self, target, follow_symlinks=follow_symlinks)
raise

flags = 0 if follow_symlinks else _winapi.COPY_FILE_COPY_SYMLINK
_winapi.CopyFile2(os.fspath(self), os.fspath(target), flags)
_winapi.CopyFile2(os.fspath(self), target, flags)

def chmod(self, mode, *, follow_symlinks=True):
"""
Expand Down