[WIP] GH-73991: Add os.copy() and friends - #119079
Conversation
Move these low-level file copy functions from `shutil` to `os`: - `copyfileobj()` - `copyfile()` - `copymode()` - `copystat()` The names remain in `shutil` for backwards compatibility. The higher level functions (which resemble the `cp` shell utility) also remain in `shutil`.
|
I'm fine with that. Suggest we move |
|
Having seen the (rough) patch, do you think it's worth it? To me it seems like an awful lot of churn just to kick some low-level functions out of |
os.copyfile() and friendsos.copy() and friends
Yes, only The new support for |
|
I am strictly against these changes. |
|
|
@zooba, I just noticed that the base system function This makes it more tempting to implement
The presence of extended attributes could be ignored, I suppose, since the Windows API provides no way to query or explicitly set them. In practice, probably the most common extended attributes are in the reserved "$KERNEL.*" namespace. Those can't be copied or set from user mode. Other extended attributes will be copied, such as the "$CI.CATALOGHINT" extended attribute that Microsoft sets on distributed files. As discussed in past issues,
|
Copy is getting a decent amount of attention in Windows right now, as we identified it as a significant potential perf improvement when the kernel knows that a plain copy is happening (e.g. AV can ignore the writes if it's already scanned the source; ReFS can use copy-on-write by default, etc.). So it's worth using the native functions wherever we can. But still, I really dislike the semantics of most of our copy functions. They seem to have been derived from the fact that our implementation used open/write rather than anything native, and I suspect if we'd gone native in the first place that we'd have defined it as "behaves like a native OS copy". So IMHO, any new copy function should be "as close to standard OS copy semantics as possible when feasible" (whether that's Anyone can use Python to open/write copy a file, but only we can make it use the OS functions (ignoring ctypes). We should do the thing we can do, and let people who want generic behaviour write it themselves. |
|
FWIW I agree completely! Picking another language/runtime at random, rust has What should we do to progress this @zooba? Do you think I should create a forum thread, or move straight to a issue titled "Add |
Unfortunately, my first instinct is that a "do what the platform does" function belongs in... But perhaps what we could do is make it private in |
|
Thanks very much Steve. I've played around with adding it privately to |

Move these low-level file copy functions from
shutiltoos:copyfileobj()copyfile()copymode()copystat()copy2()(ascopy(), minus support for copying into a destination directory)The names remain in
shutilfor backwards compatibility.📚 Documentation preview 📚: https://cpython-previews--119079.org.readthedocs.build/