GH-73991: Prune pathlib.Path.copy() and copy_into() arguments (#123337)

Remove *ignore* and *on_error* arguments from `pathlib.Path.copy[_into]()`,
because these arguments are under-designed. Specifically:

- *ignore* is appropriated from `shutil.copytree()`, but it's not clear
  how it should apply when the user copies a non-directory. We've changed
  the callback signature from the `shutil` version, but I'm not confident
  the new signature is as good as it can be.
- *on_error* is a generalisation of `shutil.copytree()`'s error handling,
  which is to accumulate exceptions and raise a single `shutil.Error` at
  the end. It's not obvious which solution is better.

Additionally, this arguments may be challenging to implement in future user
subclasses of `PathBase`, which might utilise a native recursive copying
method.
This commit is contained in:
Barney Gale 2024-08-26 17:05:34 +01:00 committed by GitHub
parent 033d537cd4
commit 7bd6ebf696
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 108 deletions

View file

@ -1540,7 +1540,7 @@ Copying, moving and deleting
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. method:: Path.copy(target, *, follow_symlinks=True, dirs_exist_ok=False, \
preserve_metadata=False, ignore=None, on_error=None)
preserve_metadata=False)
Copy this file or directory tree to the given *target*, and return a new
:class:`!Path` instance pointing to *target*.
@ -1563,21 +1563,11 @@ Copying, moving and deleting
This argument has no effect when copying files on Windows (where
metadata is always preserved).
If *ignore* is given, it should be a callable accepting one argument: a
source file or directory path. The callable may return true to suppress
copying of the path.
If *on_error* is given, it should be a callable accepting one argument: an
instance of :exc:`OSError`. The callable may re-raise the exception or do
nothing, in which case the copying operation continues. If *on_error* isn't
given, exceptions are propagated to the caller.
.. versionadded:: 3.14
.. method:: Path.copy_into(target_dir, *, follow_symlinks=True, \
dirs_exist_ok=False, preserve_metadata=False, \
ignore=None, on_error=None)
dirs_exist_ok=False, preserve_metadata=False)
Copy this file or directory tree into the given *target_dir*, which should
be an existing directory. Other arguments are handled identically to