Skip to content

Commit 5c1837c

Browse files
committed
hashcode should be kept constant after the object's creation
1 parent 5cc07b6 commit 5c1837c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pomdp_py/framework/oopomdp.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ cdef class ObjectState(State):
7474
"""__setitem__(self, attr, value)
7575
Sets the attribute `attr` to the given value."""
7676
self.attributes[attr] = value
77-
self._hashcache = -1
7877

7978
def __len__(self):
8079
return len(self.attributes)
@@ -109,10 +108,10 @@ cdef class OOState(State):
109108

110109
@property
111110
def situation(self):
112-
"""situation(self)
111+
"""situation(selppf)
113112
This is a `frozenset` which can be used to identify
114113
the situation of this state since it supports hashing."""
115-
return self._situation
114+
return frozenset(self.object_states.items())
116115

117116
def __str__(self):
118117
return '%s::[%s]' % (str(self.__class__.__name__),

tests/test_hashing_pickling.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def test_hashing_pickling():
2121
objstate3 = objstate1.copy()
2222
assert hash(objstate3) == hash(objstate1)
2323
objstate3["color"] = "green"
24-
assert hash(objstate3) != hash(objstate1)
24+
# hashcode should be kept constant after the object's creation
25+
assert hash(objstate3) == hash(objstate1)
2526
assert objstate3 != objstate1
2627

2728
oos1 = pomdp_py.OOState({1:objstate1, 2:objstate2})

0 commit comments

Comments
 (0)