[Python-ideas] issubclass(collections.OrderedDict, collections.Sequence)

Ram Rachum ram at rachum.com
Sun Oct 5 22:56:40 CEST 2014


Ok, makes sense. Though it still would be nice to have a general way to
check whether a collection is ordered or not, regardless of index access.
Perhaps a `collections.Ordered`?

On Sun, Oct 5, 2014 at 11:53 PM, Guido van Rossum <guido at python.org> wrote:

> On Sun, Oct 5, 2014 at 11:40 AM, Ram Rachum <ram at rachum.com> wrote:
>
>> I was just going to test whether a mapping is dict-like or an
>> OrderedDict-like object by doing this:
>>
>>     isinstance(x, collections.Sequence)
>>
>> But then I checked and saw that this is False:
>>
>>     issubclass(collections.OrderedDict, collections.Sequence) is False
>>
>> Why isn't an OrderedDict a Sequence?
>>
>
> Check the interface of Sequence. It requires indexing behavior that
> OrdedDict doesn't have -- a[i] is a key lookup in the underlying dict, not
> an indexed lookup in the ordered list of elements. I don't think it would
> be wise to attempt to add that behavior either (given that the keys may
> well be integers).
>
> --
> --Guido van Rossum (python.org/~guido)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141005/e4ff4a88/attachment.html>


More information about the Python-ideas mailing list