[Python-Dev] Defining a path protocol
njs at pobox.com
Thu Apr 7 14:44:30 EDT 2016
On Apr 7, 2016 10:00 AM, "Chris Barker" <chris.barker at noaa.gov> wrote:
> On Thu, Apr 7, 2016 at 12:00 AM, INADA Naoki <songofacandy at gmail.com>
>> I feel adding protocol only for path is bit over engineering. So I'm
-0.5 on adding __fspath__.
>> I'm +1 on adding general protocol for *coerce to string* like __index__.
> isn't __str__ the protocol for "coerce to string" ?
> __index__ is a protocol for "coerce to an integer that can be used as an
index", which is like __fspath__ would be "coerce to a string that can be
used as a path"
No, __index__ is the protocol for "do a safe coerce to integer". The name
is misleading, but its use in non-indexing contexts is well established.
" ab" * obj
will return a string with obj.__index__() repetitions.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev