10000 GH-73991: Add `pathlib.Path.copy()` by barneygale · Pull Request #119058 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-73991: Add pathlib.Path.copy() #119058

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 19 commits into from
Jun 14, 2024
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
0