[Python-Dev] Pathlib enhancements - acceptable inputs and outputs for fspath and os.fspath() (original) (raw)
Koos Zevenhoven k7hoven at gmail.com
Wed Apr 20 06:19:50 EDT 2016
- Previous message (by thread): [Python-Dev] Pathlib enhancements - acceptable inputs and outputs for __fspath__ and os.fspath()
- Next message (by thread): [Python-Dev] Pathlib enhancements - acceptable inputs and outputs for __fspath__ and os.fspath()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Apr 20, 2016 at 6:16 AM, Stephen J. Turnbull <stephen at xemacs.org> wrote:
(1) some really attractive producer of pathlib.Paths will be published, and
Yes, pathlib is str-only, so this sounds just right.
(2) people will want to plug that producer into their bytes paths consumers using os.fspath(path) "and be done with it".
No, fspath can't know that is the the right thing to do. There should be someone that is aware of the encoding that happens, either the provider or the consumer. That byte path consumer, assuming it wants to support the behavior you describe, should use os.fsencode instead of os.fspath, which will do exactly what you want, and just as easy for the bytes path consumer to implement!
(Unless you want to explicitly reject plain str objects, which you would then indeed do explicitly, but I'm not sure there is a point in accepting plain bytes and str-based pathlib objects but not str).
To avoid further unnecessary discussion, please read [1] carefully, where I already explained this, among other things.
-Koos
[1] https://mail.python.org/pipermail/python-dev/2016-April/144239.html
- Previous message (by thread): [Python-Dev] Pathlib enhancements - acceptable inputs and outputs for __fspath__ and os.fspath()
- Next message (by thread): [Python-Dev] Pathlib enhancements - acceptable inputs and outputs for __fspath__ and os.fspath()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]