From: Robert Jordens Date: Sun, 17 Aug 2014 20:56:31 +0000 (-0600) Subject: Signal.__getitem__: raise TypeError and IndexError when appropriate X-Git-Tag: 24jan2021_ls180~2099^2~319 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6036fffef2f8be0afb6b82203a4dd56489dbd178;p=litex.git Signal.__getitem__: raise TypeError and IndexError when appropriate --- diff --git a/migen/fhdl/structure.py b/migen/fhdl/structure.py index 3edc2860..ba84dd85 100644 --- a/migen/fhdl/structure.py +++ b/migen/fhdl/structure.py @@ -81,17 +81,20 @@ class Value(HUID): def __getitem__(self, key): from migen.fhdl.bitcontainer import flen + n = flen(self) if isinstance(key, int): + if key >= n: + raise IndexError if key < 0: - key += flen(self) + key += n return _Slice(self, key, key+1) elif isinstance(key, slice): - start, stop, step = key.indices(flen(self)) + start, stop, step = key.indices(n) if step != 1: return Cat(self[i] for i in range(start, stop, step)) return _Slice(self, start, stop) else: - raise KeyError + raise TypeError def eq(self, r): """Assignment