Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-132322: Ensure shutil functions return str when using pathlib#132820

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
rpxchoudhury wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
fromrpxchoudhury:132322-shutil-pathlib-return
Open
Show file tree
Hide file tree
Changes fromall 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
20 changes: 10 additions & 10 deletionsLib/shutil.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -310,7 +310,7 @@ def copyfile(src, dst, *, follow_symlinks=True):
if _HAS_FCOPYFILE:
try:
_fastcopy_fcopyfile(fsrc, fdst, posix._COPYFILE_DATA)
return dst
returnos.fspath(dst)
except _GiveupOnFastCopy:
pass
# Linux / Android / Solaris
Expand All@@ -319,20 +319,20 @@ def copyfile(src, dst, *, follow_symlinks=True):
if _USE_CP_COPY_FILE_RANGE:
try:
_fastcopy_copy_file_range(fsrc, fdst)
return dst
returnos.fspath(dst)
except _GiveupOnFastCopy:
pass
if _USE_CP_SENDFILE:
try:
_fastcopy_sendfile(fsrc, fdst)
return dst
returnos.fspath(dst)
except _GiveupOnFastCopy:
pass
# Windows, see:
# https://github.com/python/cpython/pull/7160#discussion_r195405230
elif _WINDOWS and file_size > 0:
_copyfileobj_readinto(fsrc, fdst, min(file_size, COPY_BUFSIZE))
return dst
returnos.fspath(dst)

copyfileobj(fsrc, fdst)

Expand All@@ -343,7 +343,7 @@ def copyfile(src, dst, *, follow_symlinks=True):
else:
raise

return dst
returnos.fspath(dst)

def copymode(src, dst, *, follow_symlinks=True):
"""Copy mode bits from src to dst.
Expand DownExpand Up@@ -481,7 +481,7 @@ def copy(src, dst, *, follow_symlinks=True):
dst = os.path.join(dst, os.path.basename(src))
copyfile(src, dst, follow_symlinks=follow_symlinks)
copymode(src, dst, follow_symlinks=follow_symlinks)
return dst
returnos.fspath(dst)

def copy2(src, dst, *, follow_symlinks=True):
"""Copy data and metadata. Return the file's destination.
Expand All@@ -505,7 +505,7 @@ def copy2(src, dst, *, follow_symlinks=True):
flags |= _winapi.COPY_FILE_COPY_SYMLINK
try:
_winapi.CopyFile2(src_, dst_, flags)
return dst
returnos.fspath(dst)
except OSError as exc:
if (exc.winerror == _winapi.ERROR_PRIVILEGE_NOT_HELD
and not follow_symlinks):
Expand All@@ -521,7 +521,7 @@ def copy2(src, dst, *, follow_symlinks=True):

copyfile(src, dst, follow_symlinks=follow_symlinks)
copystat(src, dst, follow_symlinks=follow_symlinks)
return dst
returnos.fspath(dst)

def ignore_patterns(*patterns):
"""Function that can be used as copytree() ignore parameter.
Expand DownExpand Up@@ -599,7 +599,7 @@ def _copytree(entries, src, dst, symlinks, ignore, copy_function,
errors.append((src, dst, str(why)))
if errors:
raise Error(errors)
return dst
returnos.fspath(dst)

def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2,
ignore_dangling_symlinks=False, dirs_exist_ok=False):
Expand DownExpand Up@@ -930,7 +930,7 @@ def move(src, dst, copy_function=copy2):
else:
copy_function(src, real_dst)
os.unlink(src)
return real_dst
returnos.fspath(real_dst)

def _destinsrc(src, dst):
src = os.path.abspath(src)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
shutil.copy, copy2, copyfile, copytree, and move now consistently return str even when passed pathlib.Path arguments.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Use Sphinx refs:

Suggested change
shutil.copy,copy2,copyfile,copytree, and move now consistently return str even when passed pathlib.Path arguments.
:func:`shutil.copy`,:func:`~shutil.copy2`,:func:`~shutil.copyfile`,:func:`~shutil.copytree`, and:func:`~shutil.move` now consistently return:class:`str` even when passed:class:`pathlib.Path` arguments.

Loading

[8]ページ先頭

©2009-2025 Movatter.jp