Skip to content

adafruit_dotstar __getitem__ applies incorrect cap to range input #9

@kevinjwalters

Description

@kevinjwalters

I'm a little new to Python this so I may be wrong here but I think adafruit_dotstar's getitem method is attempting to cap the range of the slice values using:

range(*index.indices(len(self._buf) // 4)):

But the length cannot be determined correctly with a simple division because of the header and trailer data in the buffer for dotstars. Perhaps this code was cut and paste from other code which has no header data in buffer?

self._n looks like a suitable (calculation-free) substitute here? I see setitem uses len(self) which looks correct but you may wish to avoid the method call given the hardware this typically runs on. Either way, a consistent approach across class would make code easier to read.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions