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: pathlib.Path should have a copy() method
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.4, Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: jshholland, paul.moore, pitrou, serhiy.storchaka
Priority: normal Keywords:

Created on 2015-05-18 16:35 by jshholland, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (6)
msg243494 - (view) Author: Josh Holland (jshholland) Date: 2015-05-18 16:35
Path objects already have rename() and replace() methods; it would be useful for them also to have a copy() method to simplify that operation.

I'll look into putting a patch together this evening.
msg243495 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-05-18 16:37
Path objects are immutable, so the copy method is not needed.
msg243515 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2015-05-18 18:45
I presume the copy method is intended as a file copy, not for copying the object. But calling the method copy() is likely to be confusing, precisely as happened here :-)
msg243517 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2015-05-18 18:51
If copy() has a mandatory argument, it can't really be mixed up with an object-cloning method.
msg243521 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-05-18 19:07
File renaming is simple and usually atomic operation. File copying is complex operation. What memory buffer should be used for copying? What to do with growing files or reading with errors? Should file space be preallocated before copyiong to decrease fragmentation? How handle sparse files? Can be optimized copyiong on file systems with compression? What to do with NT streams? What to do with extended attributes? What to do with directories, links and other special files?

I think that pathlib is not good place for this function (as well as for handling ZIP files or playing multimedia).
msg243583 - (view) Author: Josh Holland (jshholland) Date: 2015-05-19 12:23
Serhiy makes a series of good points, which I hadn't really considered before filing this report. It was mostly laziness on my part while dashing off a quick script - I knew I wouldn't have to deal with the edge cases so subconsciously dismissed them, especially as the code I wrote to copy was only a couple of lines.

So I'm happy for this bug to be closed with no change needed.
History
Date User Action Args
2022-04-11 14:58:17adminsetgithub: 68417
2016-02-24 19:42:09serhiy.storchakasetstatus: open -> closed
resolution: rejected
stage: resolved
2015-05-19 12:23:55jshhollandsetmessages: + msg243583
2015-05-18 19:07:50serhiy.storchakasetmessages: + msg243521
2015-05-18 18:51:24pitrousetmessages: + msg243517
2015-05-18 18:45:40paul.mooresetnosy: + paul.moore
messages: + msg243515
2015-05-18 16:37:25serhiy.storchakasetnosy: + serhiy.storchaka, pitrou
messages: + msg243495
2015-05-18 16:35:13jshhollandcreate