Skip to content

'array.array' has no attribute 'clear' #11008

Open

Description

@NCPlayz

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.

Activity

  1. JelleZijlstra commented on Nov 10, 2023

    @JelleZijlstra
    Member

    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'
    
  2. mikeziminio commented on Feb 2, 2024

    @mikeziminio
    Contributor

    I have added the issue to the cpython repository: python/cpython#114894

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stubs: false negativeType checkers do not report an error, but should

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions