[Python-Dev] Pathlib enhancements - acceptable inputs and outputs for __fspath__ and os.fspath()

Brett Cannon brett at python.org
Wed Apr 13 12:58:22 EDT 2016

On Wed, 13 Apr 2016 at 09:19 Fred Drake <fred at fdrake.net> wrote:

> On Wed, Apr 13, 2016 at 11:09 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> > - a single os.fspath() with an allow_bytes parameter
> >   (mostly True in os and os.path, mostly False everywhere
> >   else)
> -0
> > - a str-only os.fspathname() and a str/bytes os.fspath()
> +1 on using separate functions.
> > I'm partial to the first choice as it is simplicity itself to know when
> > looking at it if bytes might be coming back by the presence or absence
> of a
> > second argument to the call; otherwise one has to keep straight in one's
> > head which is str-only and which might allow bytes (I'm not very good at
> > keeping similar sounding functions separate -- what's the difference
> between
> > shutil.copy and shutil.copy2?  I have to look it up every time).
> I do the same, but... this is one of those cases where a caller will
> usually be passing a constant directly. If passed as a positional
> argument, it'll just be confusing ("what's True?" is my usual reaction
> to a Boolean positional argument).

It would be keyword-only so this isn't even a possibility.

> If passed as a keyword argument
> with a descriptive name, it'll be longer than I'd like to see:
>     path_str = os.fspath(path, allow_bytes=True)

I think the expectation that the number of people actually directly calling
this function with that argument specified is going to be rather small, so
the common-case will simply be:

    path_str = os.fspath(path)

> Names like os.fspath() and os.fssyspath() seem good to me.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20160413/62a24e52/attachment.html>

More information about the Python-Dev mailing list