Skip to content

displayio: Empty Group does not allow insert #3129

@kmatch98

Description

@kmatch98

In debugging an issue with Label, I uncovered an unexpected error when using insert with an empty Group. Normal lists allow insert to be used on an empty list and the function is effectively equivalent to append. However when trying to insert with an empty displayio.Group, an unexpected error IndexError: Group index out of range is triggered. Due to this unexpected behavior a kludge to is required overcome this by first checking the size of the Group and then use append if the length is zero.

Here is a command line experiment that shows the bug where insert doesn't work with an empty Group:

import displayio
myGroup=displayio.Group()
myGroup2=displayio.Group()
myGroup.insert(0, myGroup2)

Here is the error that I received:

>>> myGroup.insert(0, myGroup2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: Group index out of range
>>> 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions