(original) (raw)



On Thu, Apr 7, 2016 at 2:41 AM, Brett Cannon <brett@python.org> wrote:


On Wed, 6 Apr 2016 at 10:36 Michel Desmoulin <desmoulinmichel@gmail.com> wrote:
Wouldn't be better to generalize that to a "\_\_location\_\_" protocol,
which allow to return any kind of location, including path, url or
coordinate, ip\_address, etc ?

No because all of those things have different semantic meaning. See the \_\_index\_\_ PEP for reasons why you would tightly bound protocols instead of overloading ones like \_\_int\_\_ for multiple meanings.

-Brett

https://www.python.org/dev/peps/pep-0357/

> It is not possible to use the nb\_int (and \_\_int\_\_ special method)
> for this purpose because that method is used to \*coerce\* objects
> to integers.

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\_\_.
+0.5 on inherit from str (and drop byte path support).

--
INADA Naoki <songofacandy@gmail.com>