[Python-Dev] Pathlib enhancements - acceptable inputs and outputs for __fspath__ and os.fspath()
Stephen J. Turnbull
stephen at xemacs.org
Tue Apr 19 07:55:55 EDT 2016
Ethan Furman writes:
> On 04/18/2016 12:25 PM, Stephen J. Turnbull wrote:
> > Koos Zevenhoven writes:
>
> >> After all, we want something that's *almost* exclusively str.
> >
> > But we don't want that, AFAICT. Some clearly want this API to be
> > unbiased against bytes in the same way the os APIs are unbiased,
> > because that's what we've got in the current proposal.
>
> Are we reading the same thread? For my last several replies I am
> very biased against bytes (and I know I'm not the only one).
I'm not "reinterpreting" what people *write*, I'm looking at *the APIs
they propose and advocate*. As I wrote, and you quoted.<wink/>
Except for the original proposal that only supported pathlib.Path, the
facilities advocated are actually unbiased. It's just as easy to use
bytes as str, but it's proposed not to advertise that fact. So what?
A 'my.fspath' is trivial to write, and hard to get wrong AFAICS.
Consider a truly biased alternative: __fspath__ of types like DirEntry
would return self when bytes-oriented. (This addresses the issue of
__fspath__ that coerces to str becoming a timebomb in bytes apps.)
bytes-oriented applications would have to use DirEntry.path. No
visible difference from now (you get the same API for bytes and the
same TypeError from open), and no loss, except for str-envy. So use
str! Why isn't that acceptable to you? Maybe even TOOWTDI?
I really want to know. I'm not 100% sure that's the right way to go,
mostly because Nick and Brett are signed up for polymorphism. But I
sure haven't seen any explicit arguments for polymorphism, though I've
asked for them. AFAICS, everybody just assumed that because some
related APIs are polymorphic, this one should be, too, and dove into
the problem of how to make a polymorphic API safe for Python 3.
> If the client says "I'm okay with either" then I fully expect the
> client to have code to properly handle str vs bytes after the
> fspath (or whatever it's called) call.
I would too, but, uh, examples of such clients? And no, antipathy
isn't an example -- it doesn't consume bytes, it passes them through
to the kind of client I want to hear about.
AFAICS bytes return from __fspath__ is just YAGNI. Show me something
that actually wants it.
Steve
More information about the Python-Dev
mailing list