[Python-Dev] Defining a path protocol
ethan at stoneleaf.us
Fri Apr 8 11:33:39 EDT 2016
On 04/08/2016 02:50 AM, Nick Coghlan wrote:
>> Built-in? (name is dependent on #1 if we add one)
> os.fspath (alongside os.fsencode and os.fsdecode)
I like this better.
>> Add the method/attribute to str? (I assume so, much like __index__() is on
>> int, but I have not seen it explicitly stated so I would rather clarify it)
> Makes sense
What will this do? Return a Path or a str? I don't think we need either.
>> Expand the C API to have something like PyObject_Path()?
> PyUnicode_FromFSPath, perhaps? The return type is well-defined here,
> so it can be done as an alternate constructor, and the C API
> counterparts of os.fsdecode and os.fsencode are PyUnicode functions
> (specifically PyUnicode_DecodeFSDefault and PyUnicode_EncodeFSDefault)
So this will do the same thing as os.fspath() at the C level, yes?
> It's worth summarising in a PEP at least for communications purposes -
> very easy for folks that don't follow python-dev to miss otherwise.
> Plus my specific API suggestions are pretty different from Ethan's :)
More information about the Python-Dev