On 27 December 2015 at 17:30, Serhiy Storchaka storchaka@gmail.com wrote:
On 27.12.15 08:22, Nick Coghlan wrote:
These days, without considering the presence or absence of any non-dunder methods, the core distinction between sequences, multi-dimensional arrays and arbitrary mappings really lies in the type signature of the key parameter to__getitem__ et al (assuming a suitably defined Index type hint):
MappingKey = Any DictKey = collections.abc.Hashable SequenceKey = Union[Index, slice] ArrayKey = Union[SequenceKey, Tuple["ArrayKey", ...]]
ArrayKey also includes Ellipsis.
You're right, I was mistakenly thinking that memoryview implemented tuple indexing without ellipsis support, but it actually doesn't implement multi-dimensional indexing at all - once you cast to a multi-dimensional shape, most forms of subscript lookup are no longer permitted at all by the current implementation. So a more accurate array key description would look like:
ArrayKey = Union[SequenceKey, type(Ellipsis), Tuple["ArrayKey", ...]]
(I spelled out Ellipsis to minimise confusion with the tuple-as-frozen-list typing notation)
Cheers, Nick.