Skip to content

Instantly share code, notes, and snippets.

@matyasfodor
Created July 16, 2017 21:14
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 matyasfodor/f4b4d6392ff8e1f57b606c235e7d7d62 to your computer and use it in GitHub Desktop.
Save matyasfodor/f4b4d6392ff8e1f57b606c235e7d7d62 to your computer and use it in GitHub Desktop.
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