From: whitequark Date: Thu, 27 Aug 2020 01:14:05 +0000 (+0000) Subject: hdl.ast: clarify exception message for out of bounds indexing. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2311c0592111988959a8c976b74422cf3ceba994;p=nmigen.git hdl.ast: clarify exception message for out of bounds indexing. Fixes #488. --- diff --git a/nmigen/hdl/ast.py b/nmigen/hdl/ast.py index 7d2efef..4a01bde 100644 --- a/nmigen/hdl/ast.py +++ b/nmigen/hdl/ast.py @@ -254,7 +254,7 @@ class Value(metaclass=ABCMeta): n = len(self) if isinstance(key, int): if key not in range(-n, n): - raise IndexError("Cannot index {} bits into {}-bit value".format(key, n)) + raise IndexError(f"Index {key} is out of bounds for a {n}-bit value") if key < 0: key += n return Slice(self, key, key + 1) diff --git a/tests/test_hdl_ast.py b/tests/test_hdl_ast.py index f14c07b..e6dfc49 100644 --- a/tests/test_hdl_ast.py +++ b/tests/test_hdl_ast.py @@ -187,7 +187,7 @@ class ValueTestCase(FHDLTestCase): self.assertEqual(s2.start, 3) self.assertEqual(s2.stop, 4) with self.assertRaisesRegex(IndexError, - r"^Cannot index 5 bits into 4-bit value$"): + r"^Index 5 is out of bounds for a 4-bit value$"): Const(10)[5] def test_getitem_slice(self):