-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-34260: fix docstring of shutil.copy2 #8523
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
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. When your account is ready, please add a comment in this pull request You can check yourself Thanks again for your contribution, we look forward to reviewing it! |
c4fe127
to
4d1c346
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This seems OK for me.
I've signed CLA, could you remove the CLA not signed label? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike when docstring and doc in Doc/library/shutil.rst are different:
https://docs.python.org/dev/library/shutil.html#shutil.copy2
"Identical to copy() except that copy2() also attempts to preserve all file metadata."
This documentation is wrong: the owner is not copied.
Lib/shutil.py
Outdated
@@ -384,8 +384,8 @@ def copy(src, dst, *, follow_symlinks=True): | |||
return dst | |||
|
|||
def copy2(src, dst, *, follow_symlinks=True): | |||
"""Copy data and all stat info ("cp -p src dst"). Return the file's | |||
destination. | |||
"""Copy data and stat info (mode bits, mtime, atime, flags). Return the file's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by "mode bits", I would prefer to only write "mode". I don't know what are "flags". I'm unable to find "st_flags" in os.stat_result.
I suggest to either give the full list of all copied attributes, or document which ones are not copied. But this documentation seems to be half baked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the rst. I think it is written well mostly, so only the text 'all' has been replaced to 'more', which is correct now I believe.
'mode bits' has been replaced everywhere to 'mode' as you suggested. Also, I decided to write the concrete list of what metadata is copied by copystat, and copy2() refers to it to avoid unnecessary duplicating of the docstring.
st_flags is actually returned by stat() on some systems (*bsd and osx I believe), so I kept it there (I think it is not in stat_info's repr()), with the notation that flags is only copied when os.chflags() is available and st_flags is returned by stat(). More info about chflags: https://www.freebsd.org/cgi/man.cgi?query=chflags
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
4d1c346
to
a89bc46
Compare
I have made the requested changes; please review again. Please see my comments in a reply to your comment above. |
Thanks for making the requested changes! @vstinner, @pablogsal: please review the changes made to this pull request. |
@@ -0,0 +1,2 @@ | |||
Fix docstring of ``shutil.copy2()`` to make it more specific about which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't document changes on the documentation. I would suggest to remove the NEWS entry.
Lib/shutil.py
Outdated
@@ -384,8 +394,10 @@ def copy(src, dst, *, follow_symlinks=True): | |||
return dst | |||
|
|||
def copy2(src, dst, *, follow_symlinks=True): | |||
"""Copy data and all stat info ("cp -p src dst"). Return the file's | |||
destination. | |||
"""Copy data and some metadata. Return the file's destination. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to remove "some", the next sentence is enough.
Lib/shutil.py
Outdated
@@ -366,7 +376,7 @@ def lookup(name): | |||
_copyxattr(src, dst, follow_symlinks=follow) | |||
|
|||
def copy(src, dst, *, follow_symlinks=True): | |||
"""Copy data and mode bits ("cp src dst"). Return the file's destination. | |||
"""Copy data and mode ("cp src dst"). Return the file's destination. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, I didn't notice that the existing doc already used "mode bits". Please leave this doc unchanged ;-)
Doc/library/shutil.rst
Outdated
@@ -177,7 +177,7 @@ Directory and files operations | |||
.. function:: copy2(src, dst, *, follow_symlinks=True) | |||
|
|||
Identical to :func:`~shutil.copy` except that :func:`copy2` | |||
also attempts to preserve all file metadata. | |||
also attempts to preserve more file metadata. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to remove "more".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem is that shutil.copy() still copies the mode, so it is not true that the difference is that "copy2 attempts to preserve file metadata", as copy also preserves metadata.
Anyway, I removed the 'more' word as you suggested.
a89bc46
to
691cd9a
Compare
I have made the requested changes; please review again. Could you please also add the "skip news" label to this? |
Thanks for making the requested changes! @pablogsal, @vstinner: please review the changes made to this pull request. |
@giampaolo, @gpshead: would you mind to review this PR? |
I close/reopen the issue to re-trigger CI jobs. GitHub is sick today, https://status.github.com/messages |
Thanks for making the requested changes! @gpshead, @vstinner, @pablogsal: please review the changes made to this pull request. |
"AppVeyor build failed (...) Console: Log is empty." thank you AppVeyor... |
I rescheduled the AppVeyor job. If AppVeyor doesn't pass, I cannot merge the PR. |
Sorry, @csernazs and @vstinner, I could not cleanly backport this to |
…GH-8523) Fix the documentation of copy2, as it does not copy file ownership (user and group), only mode, mtime, atime and flags. The original text was confusing to developers as it suggested that this command is the same as 'cp -p', but according to cp(1), '-p' copies file ownership as well. Clarify which metadata is copied by shutil.copystat in its docstring.. (cherry picked from commit 4f399be) Co-authored-by: Zsolt Cserna <cserna.zsolt@gmail.com>
…GH-8523) Fix the documentation of copy2, as it does not copy file ownership (user and group), only mode, mtime, atime and flags. The original text was confusing to developers as it suggested that this command is the same as 'cp -p', but according to cp(1), '-p' copies file ownership as well. Clarify which metadata is copied by shutil.copystat in its docstring.. (cherry picked from commit 4f399be) Co-authored-by: Zsolt Cserna <cserna.zsolt@gmail.com>
GH-10065 is a backport of this pull request to the 3.7 branch. |
… (GH-10065) Fix the documentation of copy2, as it does not copy file ownership (user and group), only mode, mtime, atime and flags. The original text was confusing to developers as it suggested that this command is the same as 'cp -p', but according to cp(1), '-p' copies file ownership as well. Clarify which metadata is copied by shutil.copystat in its docstring. (cherry picked from commit 4f399be)
… (GH-10068) Fix the documentation of copy2, as it does not copy file ownership (user and group), only mode, mtime, atime and flags. The original text was confusing to developers as it suggested that this command is the same as 'cp -p', but according to cp(1), '-p' copies file ownership as well. Clarify which metadata is copied by shutil.copystat in its docstring. (cherry picked from commit 4f399be)
…GH-8523) Fix the documentation of copy2, as it does not copy file ownership (user and group), only mode, mtime, atime and flags. The original text was confusing to developers as it suggested that this command is the same as 'cp -p', but according to cp(1), '-p' copies file ownership as well. Clarify which metadata is copied by shutil.copystat in its docstring.. (cherry picked from commit 4f399be) Co-authored-by: Zsolt Cserna <cserna.zsolt@gmail.com>
… (GH-10071) Fix the documentation of copy2, as it does not copy file ownership (user and group), only mode, mtime, atime and flags. The original text was confusing to developers as it suggested that this command is the same as 'cp -p', but according to cp(1), '-p' copies file ownership as well. Clarify which metadata is copied by shutil.copystat in its docstring. (cherry picked from commit 4f399be)
Fix the docstring of copy2, as it does not copy file ownership (user and
group), just only mode bits, mtime, atime and flags.
The original text was confusing to developers as it suggested that this
command is the same as 'cp -p', but according to cp(1), '-p' copies file
ownership as well.
https://bugs.python.org/issue34260