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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
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 . |
|
|