Changes between Initial Version and Version 1 of Ticket #26769, comment 4


Ignore:
Timestamp:
11/27/18 13:31:02 (12 months ago)
Author:
embray
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #26769, comment 4

    initial v1  
    66This is different from the Python level `collections.abc` "Sequence" ABC which requires that both `__getitem__` and `__len__` are implemented.
    77
    8 This inconsistent overloading of terms is irritating and confusing, but it is what it is.  So this interface defines my own sort of middle-ground which is closer to the ABC in that it requires the C-level sequence interface (which Python classes that implement `__getitem__` have).  Unfortunately, at the Python level there is no way to explicitly distinguish between a "sequence" and a "mapping".
     8This inconsistent overloading of terms is irritating and confusing, but it is what it is.  So this interface defines my own sort of middle-ground which is closer to the ABC in that it requires both the C-level sequence interface (which Python classes that implement `__getitem__` have), but also that `PySequence_Length` works and returns a non-negative integer.  There is an assumption then that `obj[n]` will work for `[0:len(obj)]`.  Unfortunately, for types defined at the Python level there is no obvious way to explicitly distinguish between a "sequence" and a "mapping".
    99
    1010A class that implements a custom `__getitem__` may work as one or the other, or both, so the best we can do is check for `__getitem__` and `__len__` and hope it works "like a list", which is how I'm defining "sequence" in this case.