Skip to content

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

Merged
merged 1 commit into from
Oct 23, 2018

Conversation

csernazs
Copy link
Contributor

@csernazs csernazs commented Jul 28, 2018

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

@the-knights-who-say-ni
Copy link

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
and a Python core developer will remove the CLA not signed label
to make the bot check again.

You can check yourself
to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@pablogsal pablogsal added the docs Documentation in the Doc dir label Jul 28, 2018
Copy link
Contributor

@BoboTiG BoboTiG left a 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.

@csernazs
Copy link
Contributor Author

I've signed CLA, could you remove the CLA not signed label?
https://bugs.python.org/user?@template=clacheck&github_names=csernazs

Copy link
Member

@vstinner vstinner left a 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
Copy link
Member

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.

Copy link
Contributor Author

@csernazs csernazs Jul 31, 2018

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

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@csernazs
Copy link
Contributor Author

I have made the requested changes; please review again.

Please see my comments in a reply to your comment above.

@bedevere-bot
Copy link

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
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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 ;-)

@@ -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.
Copy link
Member

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".

Copy link
Contributor Author

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.

@csernazs
Copy link
Contributor Author

csernazs commented Aug 1, 2018

I have made the requested changes; please review again.

Could you please also add the "skip news" label to this?
Also, the devguide would need to be updated at some point in the future as it says nothing about "no news file is needed for documentation-only changes".

@bedevere-bot
Copy link

Thanks for making the requested changes!

@pablogsal, @vstinner: please review the changes made to this pull request.

@vstinner
Copy link
Member

vstinner commented Aug 1, 2018

@giampaolo, @gpshead: would you mind to review this PR?

@vstinner vstinner closed this Oct 22, 2018
@vstinner vstinner reopened this Oct 22, 2018
@vstinner
Copy link
Member

I close/reopen the issue to re-trigger CI jobs. GitHub is sick today, https://status.github.com/messages

@bedevere-bot
Copy link

Thanks for making the requested changes!

@gpshead, @vstinner, @pablogsal: please review the changes made to this pull request.

@vstinner
Copy link
Member

"AppVeyor build failed (...) Console: Log is empty." thank you AppVeyor...

@vstinner
Copy link
Member

I rescheduled the AppVeyor job. If AppVeyor doesn't pass, I cannot merge the PR.

@vstinner vstinner merged commit 4f399be into python:master Oct 23, 2018
@miss-islington
Copy link
Contributor

Thanks @csernazs for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @csernazs and @vstinner, I could not cleanly backport this to 3.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 4f399be0e70d8b5516b6213568b7665765bb3114 3.7

@vstinner
Copy link
Member

@csernazs: Oh, the backport failed. Can you please try to backport the change using " cherry_picker 4f399be 3.7" (see previous comment) or using "git cherry-pick -x 4f399be"?

IMHO this change also deserves to be backported to 2.7 and 3.6 as well.

csernazs added a commit to csernazs/cpython that referenced this pull request Oct 23, 2018
…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>
csernazs added a commit to csernazs/cpython that referenced this pull request Oct 23, 2018
…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>
@bedevere-bot
Copy link

GH-10065 is a backport of this pull request to the 3.7 branch.

vstinner pushed a commit that referenced this pull request Oct 23, 2018
… (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)
vstinner pushed a commit that referenced this pull request Oct 23, 2018
… (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)
csernazs added a commit to csernazs/cpython that referenced this pull request Oct 24, 2018
…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>
vstinner pushed a commit that referenced this pull request Oct 24, 2018
… (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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants