Skip to content

Instantly share code, notes, and snippets.

@slingamn
Created May 18, 2012 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slingamn/2727459 to your computer and use it in GitHub Desktop.
Save slingamn/2727459 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
class A(object):
field = 0
def __hash__(self):
return hash(self.field)
def __eq__(self, other):
return self.field == other.field
a = A()
myset = set()
mydict = {}
myset.add(a)
mydict[a] = 1
assert a in myset
a.field = 100
assert a not in myset
assert a not in mydict
assert mydict.items() == [(a, 1)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment