[Python-Dev] Defining a path protocol (original) (raw)

Ethan Furman ethan at stoneleaf.us
Wed Apr 6 14:54:08 EDT 2016


On 04/06/2016 11:32 AM, Brett Cannon wrote:

On Wed, 6 Apr 2016 at 11:06 Ethan Furman wrote:

On 04/06/2016 10:26 AM, Brett Cannon wrote:

Now we need clear details. :) Some open questions are:

1. Name: path, fspath, or something else? fspath +1 for path, +0 for fspath (I don't know how widespread the notion that "fs" means "file system" is).

Maybe os_path then? I would rather be explicit about the type of path we are dealing with -- who knows if we won't have url_path in the future (besides Guido, of course ;)

def fspath(path): try: return path.path() except AttributeError: if isinstance(path, str): return path raise TypeError # Or NotImplementedError?

Or you can drop the isinstance() check and [...]

If the purpose of fspath() is to return a usable path-as-string then we should raise if unable to do it.

If we add str.fspath then the function becomes:

def fspath(path): return path.fspath() Which might be too simplistic for a built-in, but that also means adding it on str would potentially negate the need for a built-in.

That is an attractive option.

-- Ethan



More information about the Python-Dev mailing list