add error reports on exceptions in LFSR2
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 22 Apr 2019 10:26:00 +0000 (11:26 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 22 Apr 2019 10:26:00 +0000 (11:26 +0100)
TLB/src/LFSR2.py

index d52595f5eb086f2aa028ed9215ed2cd5eb5902d6..7031227231c27291f04d765ef03fc06af93b1658 100644 (file)
@@ -10,15 +10,15 @@ class LFSRPolynomial(set):
         def elements():
             nonlocal max_exponent
             yield 0  # 0 is always required
-            for exponent in exponents:
-                if not isinstance(exponent, int):
-                    raise TypeError()
-                if exponent < 0:
-                    raise ValueError()
-                if exponent > max_exponent:
-                    max_exponent = exponent
-                if exponent != 0:
-                    yield exponent
+            for e in exponents:
+                if not isinstance(e, int):
+                    raise TypeError("exponent %s must be an integer" % repr(e))
+                if e < 0:
+                    raise ValueError("exponent %d must not be negative" % e)
+                if e > max_exponent:
+                    max_exponent = e
+                if e != 0: # skip zeros
+                    yield e
         set.__init__(self, elements())
         self.max_exponent = max_exponent