Title: array is not a Sequence
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8, Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: berdario, ceronman, eryksun, ezio.melotti, josh.r, rhettinger, stutzbach
Priority: normal Keywords:

Created on 2015-11-26 11:34 by berdario, last changed 2019-02-27 20:32 by ceronman.

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


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)
    >>> issubclass(array.array, abc.Iterable)
    >>> issubclass(array.array, abc.Container)
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


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)

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.
Date User Action Args
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: issubclass without registration only works for "one-trick pony" collections ABCs. ->
resolution: duplicate ->
2018-11-29 18:16:39serhiy.storchakalinkissue35349 superseder
2015-11-26 12:30:58eryksunsetstatus: open -> closed

superseder: 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