Skip to content

Instantly share code, notes, and snippets.

@matyasfodor
Created July 16, 2017 21:23
Show Gist options
  • Save matyasfodor/7ccd88384f29e7f2af0798fbc007a592 to your computer and use it in GitHub Desktop.
Save matyasfodor/7ccd88384f29e7f2af0798fbc007a592 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))
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