En Tue, 22 Dec 2009 13:56:36 -0300, John <j...@nurfuerspam.de> escribió:

another thread can remove the key prior to the has_key call; or perhaps
 edges isn't a real dictionary?


of course. But unless there is a way of using threading without being aware of it, this is not the case. Also, edges is definitely a dict (has been declared some lines before, and no obscure functions have been called in the meantime, just some adding to edges). Python would also fail on edges.keys() if edges
wasn't a dict...

Ok, then your edges are mutable:

py> class Edge:
...   def __init__(self, x):
...     self.x = x
...   def __eq__(self, other):
...     return self.x==other.x
...   def __hash__(self):
...     return hash(self.x)
...
py> e1 = Edge(1)
py> e2 = Edge(2)
py> e3 = Edge(3)
py> edges = {e1:None, e2:None, e3:None}
py> e2.x = 5
py> for e in edges.keys():
...   assert edges.has_key(e)
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
AssertionError
py> for e in edges:
...   assert e in edges
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
AssertionError

Once you compute an object's hash, it must remain immutable. Is this your problem?

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to