This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: array is not a Sequence
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: collections.abc.Reversible doesn't fully support the reversing protocol
View: 29727
Assigned To: Nosy List: berdario, ceronman, eryksun, ezio.melotti, iritkatriel, josh.r, rhettinger, stutzbach
Priority: normal Keywords:

Created on 2015-11-26 11:34 by berdario, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (7)
msg255413 - (view) Author: (berdario) Date: 2015-11-26 11:34
>>> from array import array
>>> from collections.abc import Sequence
>>> isinstance(array('I', [1]), Sequence)
False
msg255414 - (view) Author: (berdario) Date: 2015-11-26 11:43
Ok, basically `Sequence` does not implement `__subclasshook__` and is manually hardcoded to

```
Sequence.register(tuple)
Sequence.register(str)
Sequence.register(range)
Sequence.register(memoryview)
```


This is not by design, is it?
msg255415 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2015-11-26 12:30
This is a duplicate of issue 23864, i.e. only the "one-trick ponies" work:

    >>> issubclass(array.array, abc.Sized)
    True
    >>> issubclass(array.array, abc.Iterable)
    True
    >>> issubclass(array.array, abc.Container)
    True
msg335537 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2019-02-14 16:29
This should not be closed as a duplicate. Yes, array.array isn't automatically a Sequence, but since it isn't, the array module should be modified to explicitly do the equivalent of:

import _collections_abc

_collections_abc.Sequence.register(array)

so it's properly registered manually.
msg335539 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2019-02-14 16:31
Correction: It should actually be registered as a subclass of MutableSequence (which should make it a virtual subclass of Sequence too; list is only registered on MutableSequence as well).
msg335549 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2019-02-14 18:21
I had closed this issue because I thought issue 23864 would be resolved by extending the existing behavior. Three years later, still with no resolution, Guido commented on that issue that the current behavior shouldn't be extended and only the documentation should be fixed. In apparent contradiction, we now have the Collection ABC (Sized, Iterable, Container), which does implement a __subclasshook__.

    >>> issubclass(array.array, abc.Collection)
    True

Anyway, it was obviously a mistake to close this specific issue in favor of the general design problem. This problem can be easily solved via registration. The general design problem is dead in the water.
msg387160 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-02-17 15:37
This works now:

>>> from array import array
>>> from collections.abc import Sequence
>>> isinstance(array('I', [1]), Sequence)
True

It was fixed under issue29727.
History
Date User Action Args
2022-04-11 14:58:24adminsetgithub: 69923
2021-02-17 15:37:56iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg387160
resolution: duplicate

superseder: collections.abc.Reversible doesn't fully support the reversing protocol
2019-02-27 20:32:11ceronmansetnosy: + ceronman
2019-02-14 18:21:46eryksunsetmessages: + msg335549
2019-02-14 16:31:48josh.rsetmessages: + msg335539
2019-02-14 16:29:37josh.rsetversions: + Python 3.7, Python 3.8, - Python 3.5
2019-02-14 16:29:33josh.rsetstatus: closed -> open

nosy: + josh.r
messages: + msg335537

superseder: doc: issubclass without registration only works for "one-trick pony" collections ABCs. -> (no value)
resolution: duplicate -> (no value)
2018-11-29 18:16:39serhiy.storchakalinkissue35349 superseder
2015-11-26 12:30:58eryksunsetstatus: open -> closed

superseder: doc: issubclass without registration only works for "one-trick pony" collections ABCs.

nosy: + eryksun
messages: + msg255415
resolution: duplicate
stage: resolved
2015-11-26 11:43:10berdariosetmessages: + msg255414
2015-11-26 11:37:17ezio.melottisetnosy: + rhettinger, stutzbach, ezio.melotti
type: behavior
2015-11-26 11:34:09berdariocreate