typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

'array.array' has no attribute 'clear'

Open NCPlayz opened this issue 2 years ago • 2 comments

array.array inheriting from MutableSequence has some unintended consequences, such as below

import array

x = array.array("B")
x.clear()

At runtime array.array does not have .clear(). Is it meant to have a .clear() implemented? Right now at least it doesn't and the stubs give an incorrect definition.

NCPlayz avatar Nov 10 '23 02:11 NCPlayz

This should probably be considered a CPython bug: array claims to be a MutableSequence at runtime, but doesn't implement the full ABC.

>>> issubclass(array.array, collections.abc.MutableSequence)
True
>>> collections.abc.MutableSequence.clear
<function MutableSequence.clear at 0x1031579c0>
>>> array.array.clear
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'array.array' has no attribute 'clear'

JelleZijlstra avatar Nov 10 '23 03:11 JelleZijlstra

I have added the issue to the cpython repository: https://github.com/python/cpython/issues/114894

mikeziminio avatar Feb 02 '24 11:02 mikeziminio