1
0
mirror of https://github.com/myhdl/myhdl.git synced 2025-01-24 21:52:56 +08:00

intbv and Signal unhashable

This commit is contained in:
jand 2003-02-16 09:44:46 +00:00
parent 588e240308
commit 9ce961f438
6 changed files with 21 additions and 2 deletions

View File

@ -132,6 +132,10 @@ class Signal(object):
negedge = property(_get_negedge, None, None, "'posedge' access methodes") negedge = property(_get_negedge, None, None, "'posedge' access methodes")
# hashing not supported
def __hash__(self):
assert TypeError, "Signal objects are unhashable"
### operators for which delegation to current value is appropriate ### ### operators for which delegation to current value is appropriate ###
def __nonzero__(self): def __nonzero__(self):

View File

@ -102,3 +102,5 @@ In the following, a "sig" denotes an instance of the Signal class.
* A sig should have no other public attributes than those described * A sig should have no other public attributes than those described
above. above.
* Signal objects are unhashable.

View File

@ -69,7 +69,10 @@ class intbv(object):
res._len = basewidth + width res._len = basewidth + width
return res return res
# hash
def __hash__(self):
raise TypeError, "intbv objects are unhashable"
# copy methods # copy methods
def __copy__(self): def __copy__(self):
return intbv(self._val) return intbv(self._val)

View File

@ -77,6 +77,7 @@ separate type.
addition, literal bit strings are accepted in concatenations, just as addition, literal bit strings are accepted in concatenations, just as
they are in intbv constructors. they are in intbv constructors.
* intbv supports the iterator protocol to iterate on its bits; again, * intbv supports the iterator protocol to iterate on its bits; again,
this requires a known length. this requires a known length.
* intbv objects are unhashable

View File

@ -30,6 +30,11 @@ from Signal import Signal
from _simulator import _siglist from _simulator import _siglist
from intbv import intbv from intbv import intbv
class TestSignalUnhashable(TestCase):
def testSignalUnhashable(self):
self.assertRaises(TypeError, hash, Signal(3))
class SigTest(TestCase): class SigTest(TestCase):
def setUp(self): def setUp(self):

View File

@ -35,6 +35,10 @@ import operator
from intbv import intbv from intbv import intbv
concat = intbv.concat concat = intbv.concat
class TestIntbvUnhashable(TestCase):
def testIntbvUnhashable(self):
self.assertRaises(TypeError, hash, intbv(3))
class TestIntbvConcat(TestCase): class TestIntbvConcat(TestCase):