[Python-ideas] New PEP proposal -- Pathlib Module Should Contain All File Operations -- version 2

George Fischhof george at fischhof.hu
Sat Mar 17 18:49:00 EDT 2018

2018. márc. 17. 21:34 ezt írta ("Barry" <barry at barrys-emacs.org>):

On 17 Mar 2018, at 10:42, George Fischhof <george at fischhof.hu> wrote:

Hi folks,

I added the list of functions to the proposal, here is the new version.


PEP: 9999
Title: Pathlib Module Should Contain All File Operations
Author: George Fischhof <george at fischhof.hu>
Status: Draft
Type: Standards Track
Content-Type: text/x-rst
Created: 15-Mar-2018
Python-Version: 3.8
Post-History: 12-Mar-2018, 17-Mar-2018


This PEP proposes pathlib module to be a centralized place for all
file-system related operations.


Right now we have several modules that contain functions related
to file-system operations mainly the os, pathlib and shutil.
For beginners it is quite hard to remember where can he / she find
a function (copy resides in shutil, but the remove function can be
found in the os module.  (And sometimes developers with moderate
experience have to check the documentation as well.)

After the release of version 3.6 several methods became aware of
path-like object.  There are only a few ones which does not support
the path-like object.  After making these methods path-like object
aware, these functions could be added to pathlib.

With functions in pathlib the developers should not have to think
on which method (function) can be found in which module.

Makes the life easier.


For compatibility reasons the pathlib should contain wrappers to
the original functions.  The original functions should remain
at their original place.  (Or if pathlib contains the function, the
original modules should have a wrapper to it.)

List of mentioned functions

    * os.link => path.hardlink_to
      (should be named similarly to path.softlink_to)

    * os.mkfifo

    * os.readlink

    * os.remove

    * os.removedirs
      (shutil.rmtree has the same functionalaty)

I think you will find these to are a lot different.

>From high level, it is only question of implementation: the main goal is to
remove a chain of directories

    * os.truncate

    * shutil.copyfileobj

This function does not take paths as arguments. I guess it does not belong

No path, it is true (right now), but it has sense to have this function
among the others.

    * shutil.copyfile

    * shutil.copymode

    * shutil.copystat

    * shutil.copy

    * shutil.copy2

    * shutil.copytree with shutil.ignore_patterns

    * shutil.move

    * shutil.disk_usage

    * shutil.chown

Is yout plan to also expose all the constants need to use chmod etc from

Of course, because this PEP is about conveniece and easyness.

All functions from os module accept path-like objects,
and none of the shutil functions.

Should shutils be improved to accept path-like first?

Maybe. The PEP should show the goal. This is just a task among others to
achieve the goal. But it can be done simultanuosly.




This document has been placed in the public domain.

   Local Variables:
   mode: indented-text
   indent-tabs-mode: nil
   sentence-end-double-space: t
   fill-column: 70
   coding: utf-8

Python-ideas mailing list
Python-ideas at python.org
Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180317/371b7182/attachment-0001.html>

More information about the Python-ideas mailing list