[Python-Dev] file system path protocol PEP (original) (raw)
Brett Cannon brett at python.org
Thu May 12 14:51:55 EDT 2016
- Previous message (by thread): [Python-Dev] file system path protocol PEP
- Next message (by thread): [Python-Dev] file system path protocol PEP
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, 12 May 2016 at 11:36 Guido van Rossum <guido at python.org> wrote:
On Thu, May 12, 2016 at 10:18 AM, Brett Cannon <brett at python.org> wrote:
On Thu, 12 May 2016 at 09:25 Guido van Rossum <guido at python.org> wrote: def fspath(p: Union[str, bytes, PathLike]) -> Union[str, bytes]: if isinstance(p, (str, bytes)): return p try: return p.fspath except AttributeError: raise TypeError(...)
Other than that I think the PEP is already in fine shape. - Bytes: I strongly believe that os.fspath() should be a thin wrapper around the fspath protocol, like next() wraps the .next protocol. It should not get into bytes vs. string politics. If your app really needs strings, call os.fsdecode(). So this is my version (unoptimized): Just to double-check, did you mean for fspath to only be an attribute in your example, or did you leave off the
()
by accident? As of right now the PEP is proposing a method for the protocol to follow common practice of using methods and in case the representation is not always pre-computed and thus not necessarily giving the wrong impression that the attribute access is cheap. But admittedly an attribute was previously proposed and there wasn't a terribly strong argument against it beyond "we historically haven't done it that way", so I'm open to swapping to an attribute if that's your preference. Whoops. Didn't mean to change that! Yes, fspath should remain a method. You can breathe again. :-)
That's a mechanical change so not exactly the most stressful aspect of this PEP. :) I'll add the attribute angle to the Rejected Ideas, though.
Anyway, with your strong preference of how to tweak os.fspath() what specifically would you like to see discussed at this point? Assuming the os.fspath() -> bytes discussion is dealt with, the only open issues listed in the PEP are the naming and placement of the ABC and how to do type hints for all of this (thanks to the dichotomy of path objects using the protocol and path-like objects which is the union of path object, str, and bytes and the joy of trying to name all of this well). -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160512/2a1f589f/attachment.html>
- Previous message (by thread): [Python-Dev] file system path protocol PEP
- Next message (by thread): [Python-Dev] file system path protocol PEP
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]