Created
July 16, 2017 21:14
-
-
Save matyasfodor/f4b4d6392ff8e1f57b606c235e7d7d62 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)) | |
# ... | |
cls_attrs = dict(__slots__ = field_names, | |
__init__ = __init__, | |
__iter__ = __iter__, | |
__repr__ = __repr__, | |
__hash__ = __hash__, | |
_asdict = _asdict) | |
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