Created
May 18, 2012 20:30
-
-
Save slingamn/2727459 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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