[myhdl-list] Re: possible improvement for error message?
Brought to you by:
jandecaluwe
|
From: Jan D. <ja...@ja...> - 2005-12-08 08:51:16
|
Günter Dannoritzer wrote:
> Jan,
>
> When feeding test data from a csv file to a myhdl testbench I got the
> following error message:
>
>
> File "/usr/lib/python2.4/site-packages/myhdl/_Signal.py", line 172, in
> _set_next
> self._setNextVal(val)
> File "/usr/lib/python2.4/site-packages/myhdl/_Signal.py", line 206, in
> _setNextBool
> raise ValueError("Expected value 0 or 1, got %s" % val)
> ValueError: Expected value 0 or 1, got 1
>
>
> What happened is that I did not think about converting the data from the
> python csv reader, which delivers the data as str type, into int type.
>
> I think the following change could improve the error message:
>
>
> Index: _Signal.py
> ===================================================================
> --- _Signal.py (revision 1.29)
> +++ _Signal.py (work copy)
> @@ -202,6 +202,8 @@
>
> # set next methods
> def _setNextBool(self, val):
> + if not isinstance(val, (bool, int, long, intbv)):
> + raise TypeError("Expected bool, int, long, or intbv, got
> %s"%type(val))
> if not val in (0, 1):
> raise ValueError("Expected value 0 or 1, got %s" % val)
> self._next = val
Thanks. To avoid the additional test, I have integrated the type
info in the ValueError message and I use repr(val) to have a string
represention with quotes.
Jan
--
Jan Decaluwe - Resources bvba - http://www.jandecaluwe.com
Losbergenlaan 16, B-3010 Leuven, Belgium
From Python to silicon:
http://myhdl.jandecaluwe.com
|