[Python-Dev] pathlib - current status of discussions (original) (raw)
Ethan Furman ethan at stoneleaf.us
Thu Apr 14 10:54:39 EDT 2016
- Previous message (by thread): [Python-Dev] pathlib - current status of discussions
- Next message (by thread): [Python-Dev] pathlib - current status of discussions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 04/14/2016 05:16 AM, Victor Stinner wrote:
I consider that the final goal of the whole discussion is to support something like:
path = os.path.join(pathlibpath, "strpath", direntry) Even if direntry uses a bytes filename. I expect genericpath.join() to be patched to use os.fspath(). If os.fspath() returns bytes, path.join() will fail with an annoying TypeError. I expect that DirEntry.fspath uses os.fsdecode() to return str, just to make my life easier.
This would be where we strongly disagree. If pathlib, as a high-level construct, wants to take that approach I have no issues, but the functions in os are low-level and as such should not be changing data types unless I ask for it. I see fspath as a retrieval mechanism, not a data-transformation mechanism.
You can apply the same rationale for the flavors 2 and 3 (os.fspath(path, allowbytes=True)). Indirectly, you will get similar TypeError on os.path.join().
And that's fine. Low-level interfaces should not change data types unless explicitly requested -- and we have fsencode() and fsdecode() for that.
--
Ethan
- Previous message (by thread): [Python-Dev] pathlib - current status of discussions
- Next message (by thread): [Python-Dev] pathlib - current status of discussions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]