This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Return destination values in some shutil functions
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brian.curtin Nosy List: brian.curtin, eric.araujo, hynek, python-dev
Priority: normal Keywords: needs review, patch

Created on 2012-05-10 19:26 by brian.curtin, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
shutil_return_values.diff brian.curtin, 2012-05-10 19:26 review
issue14772.diff brian.curtin, 2012-05-10 20:27 review
issue14772_v2.diff brian.curtin, 2012-05-10 20:41 review
Messages (12)
msg160363 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2012-05-10 19:26
Attached is a patch to return the final destination of files or directories sent through shutil's copy, copy2, and move functions. This removes the need to construct the destination path on your own.

This is especially useful for copy/copy2 where you copy a file into a directory and need to know that resulting path. Rather than calling os.path.join(dest, os.path.basename(source)) you could get that path from copy/copy2 (which does that join internally).

Patch has docs and tests.
msg160370 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2012-05-10 20:27
Here's a patch that fixes the trailing whitespace Hynek noticed as well as adds an additional test case for copy/copy2.
msg160371 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2012-05-10 20:41
Added another test using move as renaming the destination file.
msg160372 - (view) Author: Hynek Schlawack (hynek) * (Python committer) Date: 2012-05-10 20:45
Code LGTM, a deeper discussion happened on IRC. :)

I'd still suggest for the sake of consistency to return the destination from copytree() too, but that can be done separately.
msg160386 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-05-10 23:45
packaging/distutils2 definitely needs that; the similar functions in distutils.file_util used to return the file paths, this was lost in the conversion to shutil, and there is at least one open bug that needs it back.
msg160387 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2012-05-10 23:48
When you say "needs that", do you mean the patch as-is, or Hynek's suggestion to return consistently?
msg160390 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-05-10 23:57
I meant that packaging needs some shutil functions to return the destination, but haven’t checked to see if that includes copytree.
msg160408 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-05-11 11:40
In distutils, both copy_file and copy_tree return the destination path(s), which is needed by many commands.  In packaging there is code to compute and return those paths, as shutil functions return None; I’d love to remove that code.

The bug I was thinking about is actually about copy(_)file parameters, not return value: #13336.
msg160853 - (view) Author: Hynek Schlawack (hynek) * (Python committer) Date: 2012-05-16 12:45
Brian, are you going to update that patch so we can close this? :)
msg163129 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-06-18 23:41
New changeset 8281233ec648 by Brian Curtin in branch 'default':
Fix #14772: Return the destination from some shutil functions.
http://hg.python.org/cpython/rev/8281233ec648
msg163176 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-06-19 15:03
New changeset e8ea27ab9fa6 by Brian Curtin in branch 'default':
Add versionchanged tags for #14772 changes
http://hg.python.org/cpython/rev/e8ea27ab9fa6
msg163725 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-06-24 06:28
Thanks!
History
Date User Action Args
2022-04-11 14:57:30adminsetgithub: 58977
2012-06-24 06:28:19eric.araujosetmessages: + msg163725
2012-06-19 15:03:32python-devsetmessages: + msg163176
2012-06-18 23:45:27brian.curtinsetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2012-06-18 23:41:45python-devsetnosy: + python-dev
messages: + msg163129
2012-05-16 12:45:05hyneksetmessages: + msg160853
2012-05-11 11:40:54eric.araujosetmessages: + msg160408
2012-05-10 23:57:09eric.araujosetmessages: + msg160390
2012-05-10 23:48:19brian.curtinsetmessages: + msg160387
2012-05-10 23:45:42eric.araujosetnosy: + eric.araujo
messages: + msg160386
2012-05-10 20:45:52hyneksetmessages: + msg160372
stage: patch review -> commit review
2012-05-10 20:41:50brian.curtinsetfiles: + issue14772_v2.diff

messages: + msg160371
2012-05-10 20:27:51brian.curtinsetfiles: + issue14772.diff

messages: + msg160370
2012-05-10 19:30:54hyneksetnosy: + hynek
2012-05-10 19:26:27brian.curtincreate