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(pathlib_path, "str_path", 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, allow_bytes=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~

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to