diff --git a/src/colortools/base.py b/src/colortools/base.py index 0366843..d803da4 100644 --- a/src/colortools/base.py +++ b/src/colortools/base.py @@ -262,6 +262,10 @@ def __iter__(self): def __getitem__(self, key): if isinstance(key, int): + if key < 0: + key += len(self) + if key < 0: + raise IndexError(key) if key == 0: return self._red elif key == 1: @@ -270,11 +274,6 @@ def __getitem__(self, key): return self._blue elif key == 3: return self._alpha - elif key < 0: - key = len(self) - key - if key < 0: - raise IndexError - return self[key] else: return tuple(self[i] for i in self._RANGE[key]) raise IndexError(key)