Created
July 16, 2017 21:23
-
-
Save matyasfodor/7ccd88384f29e7f2af0798fbc007a592 to your computer and use it in GitHub Desktop.
This file contains 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
def record_factory(cls_name, field_names): | |
# ... | |
def __hash__(self): | |
try: | |
return hash(self.id) | |
except AttributeError: | |
raise TypeError('unhashable type {}'.format(cls_name)) | |
def __eq__(self, other): | |
try: | |
return hash(self) == hash(other) | |
except AttributeError: | |
return id(self) == id(other) | |
# ... | |
cls_attrs = dict(... | |
__hash__ = __hash__, | |
__eq__ = __eq__) | |
return type(cls_name, (object,), cls_attrs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment