Skip to content

Add rmtree & copy method to pathlib #92771

Closed as not planned
Closed as not planned
@Conchylicultor

Description

@Conchylicultor

Feature or enhancement

Currently pathlib is missing some shutil features: rmtree or copy

Pitch

pathlib.Path define an Interface / API that many third party modules implement:

Having a consistent API is great as I can write code for pathlib, and it is automatically compatible with all pathlib-like backends without any code changes.
(e.g. user can replace pathlib.Path by epath.Path and the function magically work with cloud storage likegs://, s3://,...).

However due to the lack of .rmtree and .copy supports, some operations are impossible. It means each pathlib-like backend who want to support recursive directory deletion or copy has to come up with their own API, leading to inconsistency.

(technically it is possible to implement some rmtree(path.Path()) implemented only using pathlib function, but this would lead in very inefficient performance on remote storage)

Defining them directly in pathlib would make them part of the standard, with well defined semantic. This would allow implementations to rely on them and to switch between pathlib-like objects.

This will be even more relevant when pathlib will provide an explicit interface that users an inherit from: https://discuss.python.org/t/make-pathlib-extensible/3428/7

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions