[Python-Dev] Maybe, just maybe, pathlib doesn't belong.

Barry Scott barry at barrys-emacs.org
Tue Apr 12 13:03:56 EDT 2016

On Mon, 11 Apr 2016 14:15:02 -0700
Ethan Furman <ethan at stoneleaf.us> wrote:

> We've pretty decided that we have two options:
> 1. remove pathlib
> 2. make the stdlib work with pathlib
> So we're trying to make option 2 work before falling back to option 1.

I have been doing a lot of porting to Python 3 and have really enjoyed
having pathlib, even in its current state.

In one of my previous projects using python 2 on linux we had to code to
handle files with names that where not utf-8. (Users could FTP a file
into the file system and it could end up non-utf-8).

Today we would have used pathlib to represent paths in the app.
But we would need to be able to detect the paths that do not following 
the fs encoding rules.

I would suggest a predicate in Path to report that the path cannot be
encoding without the use of surrogates. Not sure what to call the

This can be used by code that cares to handle converting the path into
a suitable presentation string for showing to a user. I'm assuming here
that PEP383 may not provide an presentation string that is suitable for
showing to users.

In the case of our product we refused to use files that did not encode
to utf-8 and had a UI to allow the user to fix the name. 

One reason for files that can only be represented as bytes()
being detectable I suspect is to avoid security issues. I think
if I have my black hat on I would probe a python3 app with filenames
that are non-utf-8 and see if I can break the app.


More information about the Python-Dev mailing list