From f4b013ac7338923230aa03929a69ab5761a98ef7 Mon Sep 17 00:00:00 2001 From: Charlotte Date: Sun, 2 Jul 2023 15:23:17 +1000 Subject: [PATCH] lib.data: no loop required, we return or die. --- amaranth/lib/data.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/amaranth/lib/data.py b/amaranth/lib/data.py index e0dda08..ec41029 100644 --- a/amaranth/lib/data.py +++ b/amaranth/lib/data.py @@ -674,14 +674,13 @@ class View(ValueCastable): value = self.__target[field.offset:field.offset + field.width] # Field guarantees that the shape-castable object is well-formed, so there is no need # to handle erroneous cases here. - while isinstance(shape, ShapeCastable): - if hasattr(shape, "__call__"): - value = shape(value) - if not isinstance(value, (Value, ValueCastable)): - raise TypeError("{!r}.__call__() must return a value or " - "a value-castable object, not {!r}" - .format(shape, value)) - return value + if isinstance(shape, ShapeCastable): + value = shape(value) + if not isinstance(value, (Value, ValueCastable)): + raise TypeError("{!r}.__call__() must return a value or " + "a value-castable object, not {!r}" + .format(shape, value)) + return value if Shape.cast(shape).signed: return value.as_signed() else: