On 30.09.2019 01:41, Steven D'Aprano wrote:
> [...]
> But subscripting (indexing) is a conspicuous exception. There's no ABC 
> for testing whether something supports subscripting.

+1 for adding an ABC to signal support for indexing.

BTW: Something I miss in the ABCs is the distinction between
indexing using integers for the purpose of accessing a member
by position (e.g. in a sequence) and that of indexing objects by way
of a key object (let's say a string in e.g. a mapping).

Algorithms will typically only work with one type of indexing
and the two also use different exceptions to signal "no such member":
IndexError for the positional lookups vs. KeyError for the key
object lookups.

There's no way to map this to special methods, since both mechanisms
use .__getitem__(), so the ABC would actually provide information
which you can otherwise not easily determine.

Perhaps we could have PositionIndexable and KeyIndexable for this
(or some other names). Indexable would then be their base class
and not allow for the distinction or permit both.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Oct 01 2019)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> Python Database Interfaces ...           http://products.egenix.com/
>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
________________________________________________________________________

::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/
                      http://www.malemburg.com/
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JELLH7FVTMZLNXQ2LZSZLRTQMQEM6TDZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to