deque is not a subclass of Sequence.

Peter Otten __peter__ at web.de
Thu Apr 7 05:12:26 EDT 2016


Antoon Pardon wrote:

> Second tryal, I hope the formatting doesn't get messed up now
> 
> Playing around with the collections and collections.abc modules in
> python3.4 I stumbled upon the following:
> 
>>>> from collections.abc import Sequence
>>>> from collections import deque
>>>> isinstance(list(), Sequence)
> True
>>>> isinstance(deque(), Sequence)
> False
> 
> This seems strange to me. As far as I understand, the
> documentation indicates there is no reason why deque
> shouldn't be a subclass of Sequence.
> 
> Am I missing something or can this be considered a bug?

>>> from collections import deque
>>> from collections.abc import Sequence
>>> [name for name in set(dir(Sequence)) - set(dir(deque)) if not 
name.startswith("_")]
['index']

So the index() method seems to be what is missing.




More information about the Python-list mailing list