_utils: don't crash trying to flatten() strings.

Fixes #614.
This commit is contained in:
whitequark 2021-12-11 07:39:35 +00:00
parent 0fb2b4cd39
commit de7c9acb19
2 changed files with 8 additions and 3 deletions

View file

@ -15,10 +15,10 @@ __all__ = ["flatten", "union" , "log2_int", "bits_for", "memoize", "final", "dep
def flatten(i):
for e in i:
if isinstance(e, Iterable):
yield from flatten(e)
else:
if isinstance(e, str) or not isinstance(e, Iterable):
yield e
else:
yield from flatten(e)
def union(i, start=None):

View file

@ -740,6 +740,11 @@ class CatTestCase(FHDLTestCase):
def test_cast(self):
c = Cat(1, 0)
self.assertEqual(repr(c), "(cat (const 1'd1) (const 1'd0))")
def test_str_wrong(self):
with self.assertRaisesRegex(TypeError,
r"^Object 'foo' cannot be converted to an Amaranth value$"):
Cat("foo")
class ReplTestCase(FHDLTestCase):