Issue 25737: array is not a Sequence (original) (raw)

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 .
History
Date User Action Args
2022-04-11 14:58:24 admin set github: 69923
2021-02-17 15:37:56 iritkatriel set status: open -> closednosy: + iritkatrielmessages: + resolution: duplicatesuperseder: collections.abc.Reversible doesn't fully support the reversing protocol
2019-02-27 20:32:11 ceronman set nosy: + ceronman
2019-02-14 18:21:46 eryksun set messages: +
2019-02-14 16:31:48 josh.r set messages: +
2019-02-14 16:29:37 josh.r set versions: + Python 3.7, Python 3.8, - Python 3.5
2019-02-14 16:29:33 josh.r set status: closed -> opennosy: + josh.rmessages: + superseder: doc: issubclass without registration only works for "one-trick pony" collections ABCs. -> (no value)resolution: duplicate -> (no value)
2018-11-29 18:16:39 serhiy.storchaka link issue35349 superseder
2015-11-26 12:30:58 eryksun set status: open -> closedsuperseder: doc: issubclass without registration only works for "one-trick pony" collections ABCs.nosy: + eryksunmessages: + resolution: duplicatestage: resolved
2015-11-26 11:43:10 berdario set messages: +
2015-11-26 11:37:17 ezio.melotti set nosy: + rhettinger, stutzbach, ezio.melottitype: behavior
2015-11-26 11:34:09 berdario create