[Python-Dev] Defining a path protocol

Chris Barker chris.barker at noaa.gov
Thu Apr 7 15:06:19 EDT 2016

On Thu, Apr 7, 2016 at 11:44 AM, Nathaniel Smith <njs at pobox.com> wrote:

> 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.
> E.g.
> " ab" * obj
> will return a string with obj.__index__() repetitions.
A good argument for Chris A's proposal over on python-ideas to have a
dunder method for "coerce to a lossless string", that could be used for
Path, but also for who knows what else?

As I see it , exactly the same as the __fspath__ idea, except that we'd use
a name that made it clear you might want to use it for other things (and
str would grow that method...)



Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20160407/45c2a8d3/attachment-0001.html>

More information about the Python-Dev mailing list