forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
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
>>>